簡體   English   中英

在組件回調函數里面,如何訪問當前組件的屬性,角度為2?

[英]In the component callback function inside how to access the current component of the property, in angular 2?

我有兩個組件: listComponent.tschangeStatusComponent.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM