AngularJS错误:未知的提供者

时间:2013-06-14 16:29:32

标签: javascript angularjs

我正在获得经典的错误:未知提供者: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>

我以为我是通过这本书做到的,但我收到了错误。有谁知道它会是什么?

1 个答案:

答案 0 :(得分:3)

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