AngularJS中的服务返回值问题

时间:2014-07-15 10:03:56

标签: angularjs angularjs-service

我在从Angular Service返回数据时遇到问题。以下是服务代码....

app.service('Data',function(){

var accountList = [];
var currentAccount ='Test1'; //Initialization

var bookmarkAccount = function(accountName){
    accountList.push(accountName);
}
var setPassingAccount = function(Account){
    console.log('in Service : setting current account value to '+Account);
    currentAccount = Account;
}

return{
    bookmarkAccount: bookmarkAccount,
    setPassingAccount: setPassingAccount,
    currentAccount: currentAccount,
    accountList: accountList
};
});

我能够访问“数据”中的所有方法/变量。服务除了" currentAccount"。从控制器访问它时获取空值。以下是控制器代码......

app.controller('BookmarkController',function(Data){

 this.accountList = [];
this.accountList = Data.accountList;
this.account = Data.currentAccount; //ISSUE
Console.log('Account list object'+accountList);
Console.log('Current account selected :'+this.account);
}

我可以在' accountList'中获取所有值,但是空白' currentAccount'。任何人都可以请你帮忙。

0 个答案:

没有答案