我是AngularJS的新手,我正在尝试遵循可扩展应用程序的一些结构,以及尝试使Firebase正常工作。但是,我在进样器上遇到了一个简单的错误。当我查看错误树时,它似乎是所有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
答案 0 :(得分:1)
好像你没有$scope
正确。
对于routeProvider
,它是templateUrl
而不是templateURL
。对于TeamCtrl
,如果要将对象绑定到View,请记住将此对象添加到$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>