我第一次在Angular写一个SPA应用程序,但遇到了一个问题。
我创建路线的JavaScript如下所示:
$(function() {
angular.module("myApp", ["ngRoute"])
.config(function($routeProvider) {
$routeProvider.otherwise({
templateUrl: "/angular/components/booking-system/booking-system-template.html"
});
});
});
和我的'母版页'(正确的术语是什么?)看起来像这样:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>My App</title>
<script src="/Scripts/jquery-1.10.2.min.js"></script>
<script src="/Scripts/angular.min.js"></script>
<script src="/Scripts/angular-route.min.js"></script>
<script src="/angular/scripts/route-config.js"></script>
<link href="/Content/bootstrap.min.css" rel="stylesheet" />
<link href="/Content/bootstrap-select.css" rel="stylesheet" />
</head>
<body>
<div class="container body-content">
<ng-view/>
</div>
</body>
</html>
我收到以下错误:
Failed to instantiate module myApp due to:
Error: [$injector:nomod] http://errors.angularjs.org/1.3.13/$injector/nomod?p0=ibo...
at Error (native)
at http://localhost:4685/Scripts/angular.min.js:6:417
at http://localhost:4685/Scripts/angular.min.js:21:412
at a (http://localhost:4685/Scripts/angular.min.js:21:53)
at http://localhost:4685/Scripts/angular.min.js:21:296
at http://localhost:4685/Scripts/angular.min.js:35:116
at s (http://localhost:4685/Scripts/angular.min.js:7:302)
at g (http://localhost:4685/Scripts/angular.min.js:34:399)
at ab (http://localhost:4685/Scripts/angular.min.js:38:135)
at d (http://localhost:4685/Scripts/angular.min.js:17:381
我做错了什么?请帮忙!
中号
答案 0 :(得分:1)
似乎你的自执行块有问题,因为$
符号更改了下面的代码并尝试,
(function(){
angular.module("myApp", ["ngRoute"])
.config(function($routeProvider) {
$routeProvider.otherwise({
templateUrl: "/angular/components/booking-system/booking-system-template.html"
});
});
}());