0

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

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>

我以为我是按书本做的,但我得到了错误。有谁知道会是什么?

4

1 回答 1

3

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

于 2013-06-14T16:36:47.243 回答