我在NG2中返回subscribe數組的問題很少。Typescript訂閱方法返回
我是打字機的新手,我無法理解如何在函數和構造函數之間傳遞變量。
我的代碼如下所示:
export class RosterPage extends Page {
roster:Roster[];
players:Players[];
roster_data:any;
constructor(private location: Location, private playersService: PlayersService) {
super(location);
this.players = [];
this.roster = [];
this.roster_data = this.getRoster();
for (let i of this.roster_data) {
console.log(i); // I need iterate
getRoster() {
return this.playersService.getRoster("2017","MUZ").subscribe(roster => {
this.roster = roster["soupiska"];
});
}
}
的[我如何返回從一個異步調用的響應?(可能的複製http://stackoverflow.com/questions/14220321/how-do-i-return-來自異步調用的響應) – echonax