Angularjs错误未知提供者:$ scopeProvider< - $ scope< - user

时间:2015-06-11 22:30:51

标签: javascript angularjs angularjs-factory angular-controller

我收到错误

  

未知提供商:$ userProvider< - $ user“

使用以下代码:

var app = angular.module('test', []);

app.factory("user", function($scope, $http) {
   var usr = {};
   usr.getAllLists = function(){
       return "test";
   }
   return usr;  
});

cart.controller("MyController", ["$scope", "$http", "$user", 
    function ($scope, $http, user){

        $scope.initialize = function(){
            $scope.lists = user.getAllLists();
        }

    }
]);

你看到了错误吗?

1 个答案:

答案 0 :(得分:6)

假设购物车依赖于app模块。

cart.controller("MyController", ["$scope", "$http", "user", 
    function ($scope, $http, user){

        $scope.initialize = function(){
            $scope.lists = user.getAllLists();
        }
    }

必须是用户,而不是$user

此外,在工厂中,使用$scope代替$rootScope