I'm diving into a new project involving asp.NET Web API, AngularJS, and RequireJS. I started with this seed project on GitHub but it seems to be giving me some trouble.
This is how my folder structure looks currently:
css/
main.css
normalize.css
img/
js/
controllers/
myctrl2.js
lib/
angular/
angular.js
jquery/
jquery-1.9.1.min.js
require/
require.js
text.js
app.js
controllers.js
directives.js
filters.js
main.js
routes.js
services.js
partials/
partial1.html
partial2.html
Default.cshtml
Below is my app.js:
define([
'angular',
'filters',
'services',
'directives',
'controllers'
], function (angular, filters, services, directives, controllers) {
'use strict';
return angular.module('myApp', ['myApp.controllers', 'myApp.filters', 'myApp.services', 'myApp.directives']);
});
This is my main.js:
require.config({
paths: {
jquery: 'lib/jquery/jquery-1.9.1.min',
angular: 'lib/angular/angular',
text: 'lib/require/text'
},
shim: {
'angular': { 'exports': 'angular' }
},
priority: [
"angular"
]
});
require([
'jquery',
'angular',
'app',
'routes'
], function ($, angular, app, routes) {
'use strict';
$(document).ready(function () {
var $html = $('html');
angular.bootstrap($html, ['myApp']);
$html.addClass('ng-app');
});
});
Lastly, here's the content of default.cshtml:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>360</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<script data-main="js/main" src="js/lib/require/require.js"></script>
</head>
<body>
<h1>AngularJS + RequireJS</h1>
<ul class="menu">
<li><a href="#/view1">View 1</a></li>
<li><a href="#/view2">View 2</a></li>
</ul>
<div ng-view></div>
</body>
</html>
The issue arises when Default.cshtml loads completely, stopping at <div ng-view></div>
. Nothing beyond that point loads and the <html>
tag misses the ng-app
attribute. Additionally, an error in the console reads:
Uncaught SyntaxError: Unexpected token <
Can anyone provide advice on why this might be happening? I have already tried creating the angular object on document.ready and adding the ng-app
attribute with no success.
Thank you for your help!