gpt4 book ai didi

javascript - AngularJS 路由示例给出未捕获错误 : [$injector:modulerr]

转载 作者:行者123 更新时间:2023-11-28 00:19:48 25 4
gpt4 key购买 nike

我对 Angular JS 完全陌生。我正在使用 Angular JS 版本 1.3.15这是我为路线编写的代码。但是我在 google chrome 中遇到以下异常 -

   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>

如何解决这个错误?

最佳答案

你在这里错过了几件事

  1. angular-route.min.js 的脚本引用
  2. 您的应用声明中缺少 ngRoute

代码

var app = angular.module('app',['ngRoute']);

关于javascript - AngularJS 路由示例给出未捕获错误 : [$injector:modulerr],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30140503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com