在组件回调函数里面如何访问属性的当前组件,在角度2?

时间:2017-06-19 08:04:20

标签: angular components

我有两个组件: 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
            */

    };
}

1 个答案:

答案 0 :(得分:0)

我找到了答案。

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);


    };

}