gpt4 book ai didi

javascript - AngularJS错误: Unknown provider

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

我得到了经典的经典错误:未知的提供者:UserModelProvider <-带有 Angular JS的UserModel。我的代码如下所示:

var ClabborApp = angular.module('clabbor', []);

ClabborApp.factory('UserModel', function() {
var UserModel = {};

var list = [];
UserModel.getItem = function(index) {
return list[index];
}
UserModel.addItem = function(item) {
list.push(item);
}
UserModel.removeItem = function(item) {
list.splice(list.indexOf(item), 1)
}
UserModel.size = function() {
return list.length;
}

return UserModel;

});

function FollowersCtrl($scope, UserModel) {
$scope.followers = [{
text : 'learn angular',
done : true,
'name' : 'James'
}, {
text : 'build an angular app',
done : false,
'name' : 'John'
}];
}

我的 html 看起来像这样:

<html lang="en" ng-app>
<meta charset="utf-8">
<body ng-app="clabbor">
<div class="content follow" ng-controller="FollowersCtrl">
<ul class="clearfix">
<!-- Show max 12 followers -->
<li ng-repeat="follower in followers">
{{follower.name}}
</li>
</ul>
</div>

</body>

</html>

我以为我是按照书本做的,但我收到了错误。有谁知道这可能是什么?

最佳答案

html 标记中删除 ng-app 属性。这是正在运行的 Jsfiddle:http://jsfiddle.net/eA2xx/ 。您不能拥有多个 ng-app

关于javascript - AngularJS错误: Unknown provider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17113180/

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