Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs error Unknown provider: $scopeProvider <- $scope <- user

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?

like image 731
sibe94 Avatar asked Jul 04 '26 18:07

sibe94


1 Answers

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.

like image 85
Nikhil Aggarwal Avatar answered Jul 07 '26 07:07

Nikhil Aggarwal