即使在將ngRoute文件和ngRoute包含在dependencyInjection中之後,仍然出現以下錯誤。
未捕獲的錯誤:
[$injector:modulerr] http://errors.angularjs.org/1.2.7/$injector/modulerr?p0=demoModule&p1=Error….org%2F1.2.7%2F%24injector%2Funpr%3Fp0%3D%2524routeprovider%0A%20%20%20%20...<omitted>...2)
來源:
<head>
<title>Intro to Angular js </title>
</head>
<body>
<div>
<div data-ng-view=""></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script>
<script>
var demoApp = angular.module ('demoModule' , ["ngRoute"]);
demoApp.controller ('SimpleController', function ($scope) {
$scope.persons = [ {name: "xxx", city: "St.Louis"}, {name: "yyyy", city: "NY"}, {name: "zzzz", city: "Seattle"} ];
$scope.addCustomer = function () {
$scope.persons.push ({name: $scope.customerName, city: $scope.customerCity})
}
});
demoApp.config (function ($routeprovider) {
$routeprovider
.when ('/',
{
controller: 'SimpleController',
templateUrl: 'View1.html'
})
.when ('/view2',
{
controller: 'SimpleController',
templateUrl: 'View2.html'
})
.otherwise ({ redirectTo:'/'});
});
</script>
</body>
它應該是'$ routeProvider'(camelCase)。 –