最初,我制作了一个控制器来保存数据,这对我有用。然后我将数据移到工厂。我将工厂注入控制器。我还将我的模块/控制器/工厂的地址放在我的HTML代码中,但是我收到错误"未知提供商"
这是我的工厂代码:
(function() {
var userFactory = function () {
user =
{
"objectId": "NlPjdF5yK2",
"username": "saberi.ar.eng@gmail.com",
"emailVerified": "true",
"email": "saberi.ar.eng@gmail.com",
"myOwnCards": "['zIlHxyotrV','i1OOfskc9p','pv3NeClPkb','sdNuOoa7L2']",
"name": "Alireza",
"profile": "Ali",
"surname": "Saberi",
"image": "../assests/images/people/NlPjdF5yK2.jpg"
};
var factory = {};
factory.getUser = function(){
return user;
};
return factory;
};
angular.module('ccApp').factory('userFactory', userFactory);
}());
这是我的控制器同意
(function() {
var userController = function ($scope,userFactory) {
user = {};
function init(){
$scope.user = user;
};
init();
};
userController.$inject = ['$scope','userFactory'];
angular.module('ccApp').controller('userController', userController);
}());
答案 0 :(得分:0)
我想,这就是答案:
依赖的顺序很重要。因为你正在呼叫用户 从控制器出厂,需要先加载它 控制器。