0
我怎樣才能在這個表角/打字稿值..角/打字稿:在表
我怎樣才能獲得的代碼和標籤的價值獲得值.. 我試着要做到這一點代碼,但它不是工作:
MyComponent.ts
jsonsTypes = []; // define here global variable
saveFolder() {
let tab = [];
this.adminService.getLabelByCode(code).subscribe(
labelByCode => {
tab.push({
'code': code,
'label': labelByCode.label
});
});
this.jsonTypes.push(tab);
//here when I do console.log(tab); ==> I have the result of the picture
for (var index = 0; index < this.jsonTypes.length; index++) {
console.log(jsonTypes[index]);
console.log(jsonTypes[index].code); // ==> undefined
// How can I get value ?
}
}
做內部訂閱,因爲值被賦值一次getLabelByCode(代碼)完成。你在做這個for循環,因此它通過一個空數組循環。 – trungk18
你的訂閱方法並不適合那裏。訂閱應該完成一次。 – Christian
我在我的第一篇文章中犯了錯誤 - 我編輯它 – user1814879