![](/img/trans.png)
[英]How to access component class variables inside a callback function in angular?
[英]In the component callback function inside how to access the current component of the property, in angular 2?
我有兩個組件: listComponent.ts和changeStatusComponent.ts ,它們與列表頁面listComponent.html和狀態修飾符頁面changeStatusComponent.html關聯 , listComponent.html頁面具有一個表,其中每行都有一個修改后的狀態按鈕,彈出按鈕被點擊時ChangeStatusComponent.html頁面,修改狀態並稍后保存時,listComponent.html頁面通過自動更新修改( 而不是刷新頁面 )
問題 :請參閱評論部分
listComponent.ts
changeLevel(item: any){
let res = this.dialog.open(ChangeLevelComponent);
res.componentInstance.userId = item.userId;
res.componentInstance.cb = function(item: any){
//item is Modified object({userId:xxx, level: xxx}).
/*
I want to find the corresponding record by item.id
and then modify the level attribute of the record.
But here I can not access the xxx component properties
(datas - user binding listComponent.html page table target)
*/
//changeLevel method inside this can only access the properties
//of the ChangeLevelComponent component
/*
Here's how to access the listComponent component's properties,
which are used to bind to the xxx.html table
*/
};
}
我找到了答案。
changeLevel(item: any){
var self = this;
let res = this.dialog.open(ChangeLevelComponent);
res.componentInstance.ffClassId = item.ffClassId;
res.componentInstance.cb = (item: any) => {
console.log(self.listService.list);
};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.