javascript - Pass several data from Mat Dialog Angular 4 back to parent - Stack Overflow

I have an mat dialog ponent in my project as I press Confirm button I call onCloseConfirm(data) {this.

I have an mat dialog ponent in my project as I press Confirm button I call

  onCloseConfirm(data) {
    this.thisDialogRef.close('Confirm');
    console.log("conf data", data);
  }

in my parent I subscribe to passed data (in my Case 'Confirm');

   dialogRef.afterClosed().subscribe(result => {
      console.log(`Dialog closed: ${result}`);
});

What I would like to do is to pass data also. So I would like to pass the 'Confrim' message + data both. Is it possible?

I have an mat dialog ponent in my project as I press Confirm button I call

  onCloseConfirm(data) {
    this.thisDialogRef.close('Confirm');
    console.log("conf data", data);
  }

in my parent I subscribe to passed data (in my Case 'Confirm');

   dialogRef.afterClosed().subscribe(result => {
      console.log(`Dialog closed: ${result}`);
});

What I would like to do is to pass data also. So I would like to pass the 'Confrim' message + data both. Is it possible?

Share Improve this question asked Jun 1, 2018 at 8:53 Anna FAnna F 1,6834 gold badges25 silver badges43 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You can pass anything to the close method, so you could pass something like this:

 onCloseConfirm(data) {
    this.thisDialogRef.close({
       message: 'Confirm',
       data
    });
    console.log("conf data", data);
  }

And then, in the afterClosed handler:

dialogRef.afterClosed().subscribe(result => {
  console.log(`Dialog closed: ${result.message}`, result.data);
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745654201a4638446.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信