将字符串或对象传递给angular2材质对话框组件

时间:2017-02-20 09:42:53

标签: angular angular-material2

如何传递给angular2材质对话组件?

这是要触发的html:

Google News

这是TS:

<button md-raised-button color="primary" (click)="openDialog('stupid')">ADD GIT HOST</button>

如何将slug传递给打开的对话框,以便我可以使用它? e.g。

openDialog(slug){


    let dialogRef = this.dialog.open(DialogGitHost);
    dialogRef.afterClosed().subscribe(result => {
      //this.selectedOption = result;
    });

  }

1 个答案:

答案 0 :(得分:0)

尝试传递这样的数据:

openDialog(slug){
this.dialogRef = this.dialog.open(DialogComponent, {
  disableClose: false,
  data: slug
});

并在DialogComponent中使用以下命令重新设置数据:

ngOnInit() {
this.data = this.dialogRef.config.data;
}