javascript - Angularjs error Unknown provider: $scopeProvider <- $scope <- user - Stack Overflow

I get the error Unknown provider: $userProvider <- $user" With following code:var app = angular

I get the error

Unknown provider: $userProvider <- $user"

With following code:

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();
        }

    }
]);

Do you see the mistake?

I get the error

Unknown provider: $userProvider <- $user"

With following code:

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();
        }

    }
]);

Do you see the mistake?

Share Improve this question edited Mar 3, 2016 at 15:14 JEuvin 1,0381 gold badge15 silver badges32 bronze badges asked Jun 11, 2015 at 22:30 sibe94sibe94 1351 gold badge3 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Assuming cart is having dependency on app module.

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

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

It has to be user and not $user.

Also, in factory, in place of $scope, use $rootScope.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745569540a4633597.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信