gpt4 book ai didi

AngularJS注入(inject)器错误未捕获错误: [$injector:modulerr]

转载 作者:行者123 更新时间:2023-12-02 22:31:11 27 4
gpt4 key购买 nike

我是 AngularJS 新手,我正在尝试遵循可扩展应用程序的一些结构,并尝试让 Firebase 正常工作。但是,我在注入(inject)器上遇到了一个简单的错误。当我查看错误树时,它似乎都是 AngularJS 引用,并且我在代码中没有看到对对象的引用。我想我找错地方了?

Failed to instantiate module MyApp due to:
Error: [$injector:unpr] http://errors.angularjs.org/1.3.11/$injector/unpr?p0=e
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:6:417
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:38:307
at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:36:308)
at Object.e [as invoke] (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:37:64)
at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:35:301)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:35:425
at s (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:7:302)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:35:202)
at Ob (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:38:435

This is my Plunkr sample

最佳答案

看来您没有正确理解$scope

对于 routeProvider,它是 templateUrl 而不是 templateURL。对于TeamCtrl来说,如果你想给View绑定(bind)一个对象,记得把这个对象添加到$scope中。

angular.module('MyApp').config(function($routeProvider) {
$routeProvider
.when('/', {
controller: 'TeamCtrl',
templateUrl: 'team.html'
})
.otherwise({
redirectTo: '/'
});

});

angular.module('MyApp').controller('TeamCtrl', ['$scope', '$firebase', 'Teams',
function ($scope, $firebase, Teams) {

$scope.Teams = Teams;
$scope.team = {};

$scope.SaveTeam = function(team) {
$scope.Teams.$add({
Id: $scope.team.id,
Name: $scope.team.Name,
Wins: $scope.team.Wins,
Losses: $scope.team.Losses
});
};

$scope.team.id = "";
$scope.team.Name = "";
$scope.team.Wins = "";
$scope.team.Losses = "";
}
]);

对于team.html

<div ng-repeat="team in Teams">
<h2>{{team.Name}}</h2>
{{team.Wins}} / {{team.Losses}}
</div>

关于AngularJS注入(inject)器错误未捕获错误: [$injector:modulerr],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28207136/

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