我有一个简单的例子,其中默认的one.html必须通过ng-Route可见,但我得到一个错误。
HTML:
<html>
<head>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="http://code.angularjs.org/1.2.1/angular-route.min.js"></script>
<script src= "angularScript.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div ng-view=""></div>
</body>
</html>
angularScript.js
//App Declaration
var app = angular.module('myApp', ['ng-Route'] );
//Controllers
app.controller('myCtrl', function($scope) {
});
//Routers
app.config(function($routeProvider){
$routeProvider
.when('/one', {
title: 'one',
controller: 'oneCtrl',
templateUrl: 'one.shtml'
})
.when('/two', {
title: 'two',
controller: 'twoCtrl',
templateUrl: 'two.shtml'
})
.when('/three', {
title: 'three',
controller: 'threeCtrl',
templateUrl: 'three.shtml'
})
.otherwise({
title: 'one',
redirectTo: '/one'
});
});
one.html
This is one
我正在使用ng-Route的依赖项并尝试使用ng-view在div的页面中获取默认的one.html内容,但我在控制台上收到以下错误:
未捕获错误:[$ injector:modulerr] http://errors.angularjs.org/1.3.14/ $注射器/ modulerr P0 = MyApp来&安培; P1 =错误%3A%... gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A17%3A381)
答案 0 :(得分:1)
在angularjs脚本中尝试以下代码
//App Declaration
var app = angular.module('myApp', ['ngRoute'] );
//Controllers
app.controller('myCtrl', function($scope) {
});
app.controller('oneCtrl', function($scope) {
});
//Routers
app.config(function($routeProvider){
$routeProvider
.when('/one', {
title: 'one',
controller: 'oneCtrl',
templateUrl: 'one.shtml'
})
.when('/two', {
title: 'two',
controller: 'twoCtrl',
templateUrl: 'two.shtml'
})
.when('/three', {
title: 'three',
controller: 'threeCtrl',
templateUrl: 'three.shtml'
})
.otherwise({
title: 'one',
redirectTo: '/one'
});
});
您需要在控制器中指定oneCtrl以及ngRoute