angular.module('voteApp').factory('VoteFty', function (VoteRsc, VoteStatisticRsc) {
var data = {
vote: {}
};
var view = function () {
VoteStatisticRsc.get({id: 1}, function (resp) {
data.vote = resp;
})
};
var vote = function (params) {
VoteRsc.update({id: 1, index: params}, function (resp) {
alert('ok!');
})
};
view();
return {
data: data,
vote: vote,
view: view
}
});
angular.module('voteApp').controller('VoteCtrl', function ($scope, VoteFty) {
console.log(VoteFty.data); // Object{vote:..}
console.log(VoteFty.data.vote); // Object{}
}
为什么VoteFty.data.vote为空?我真的不明白,请帮我搞清楚,谢谢!
答案 0 :(得分:0)
你可以像这样使用工厂:
angular.module('voteApp').factory( 'VoteFty', function () {
var factory = {};
var privateVar = 'something';
factory.data = function(){
//some code here like return private var ect
return privateVar;
};
return factory;
});
而且你可以使用VoteFty.data();