我是Angular JS的新手。我使用的是Angular JS 1.3.15版 这是我为路线写的代码。但是我在谷歌浏览器中遇到以下异常 -
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/$injector/modulerr?p0=app&p1=Error%3A%20…wala%2FDesktop%2FPersonal%2520Work%2FAngularJS%2Fangular.min.js%3A38%3A135
代码是 -
<html ng-app="app">
<head>
<title>Sample Angular JS application - routes example</title>
<script src="angular.min.js" type="text/javascript">
</script>
<script>
var app = angular.module('app',[]);
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
controller : 'SimpleController',
templateUrl : 'routes/view1.html'
})
.when('/view2', {
controller : 'SimpleController',
templateUrl : 'routes/view2.html'
})
.otherwise({
redirectTo: '/'
});
});
app.controller('SimpleController',['$scope',
function ($scope) {
$scope.customers = [
{name: 'Akshay Kumar' , city: 'Chandigarh'},
{name: 'Madhuri Dixit' , city: 'Mumbai'},
{name: 'Shah Rukh Khan' , city: 'Delhi'},
{name: 'Anil Kumble' , city: 'Bangalore'},
{name: 'Rishi Kanitkar' , city: 'Pune'},
{name: 'Dhanraj Pillai' , city: 'Pune'}
];
$scope.addCustomer = function() {
$scope.customers.push(
{
name: $scope.newCustomer.name ,
city: $scope.newCustomer.city
});
}
}]);
</script>
</head>
<body>
<div>
<!-- Placeholder for the views -->
<div ng-view=""></div>
</div>
</body>
</html>
如何解决此错误?
答案 0 :(得分:1)
你错过了几件事
angular-route.min.js
ngRoute
<强>代码强>
var app = angular.module('app',['ngRoute']);