我得到错误
未知提供者:$ 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();
}
}
]);
你看到错误了吗?
假设购物车依赖于应用程序模块。
cart.controller("MyController", ["$scope", "$http", "user",
function ($scope, $http, user){
$scope.initialize = function(){
$scope.lists = user.getAllLists();
}
}
它必须是用户而不是$user
。
另外,在工厂中代替$scope
使用$rootScope
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句