3

我得到错误

未知提供者:$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();
        }

    }
]);

你看到错误了吗?

4

1 回答 1

6

假设购物车依赖于应用程序模块。

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

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

它必须是 user 而不是$user

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

于 2015-06-11T22:33:11.063 回答