簡體   English   中英

AngularJS錯誤:提供程序未知

[英]AngularJS Error: Unknown provider

我正在獲得經典的經典錯誤:Unknown provider:UserModelProvider <-帶角度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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM