gpt4 book ai didi

angularjs - 为什么我收到 ' Error: [$injector:modulerr] http://errors.angularjs.org/1.2.21/$injector/modulerr'

转载 作者:行者123 更新时间:2023-12-02 23:52:55 27 4
gpt4 key购买 nike

<html ng-app="demoapp">
<head>
<script type="text/javascript" src="../angular.min.js"></script>
<script type="text/javascript">
var demoapp = angular.module('demoapp', []);

demoapp.controller('SimpleController',function ($scope){
$scope.customer = [
{name: "Deepak" , city: "Bhubaneswar"},
{name: "Sivaji" , city: "Banglore"}
];
$scope.addCustomer = function($scope){
$scope.customer.push({ name: $scope.newCustomer.name ,city: $scope.newCustomer.city});
}
});

demoapp.config(function ($routeProvider){
$routeProvider
.when('/',{
controller: 'SimpleController',
templateUrl: 'Partials/view1.html'
})
.when('/view2',{
controller: 'SimpleController',
templateUrl: 'Partials/view2.html'
})
.otherwise({redirectTo: '/'});
});

</script>
</head>
<body>
<div ng-view=""></div>
</body>

有人可以建议我这里出了什么问题吗?为什么我收到错误。我是 Angular 的新手,请帮忙。我认为配置部分存在一些问题。但我无法调试它。

最佳答案

添加 Angular 路由脚本

<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.min.js"></script>

添加 ngRoute 作为依赖项

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

你应该像这样定义 Controller 。

demoapp.controller('SimpleController',["$scope", function ($scope){
$scope.customer = [
{name: "Deepak" , city: "Bhubaneswar"},
{name: "Sivaji" , city: "Banglore"}
];
$scope.addCustomer = function($scope){
$scope.customer.push({ name: $scope.newCustomer.name ,city: $scope.newCustomer.city});
}
}]);

关于angularjs - 为什么我收到 ' Error: [$injector:modulerr] http://errors.angularjs.org/1.2.21/$injector/modulerr',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25249580/

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