【问题标题】:pass string or object to angular2 material Dialog component将字符串或对象传递给 angular2 材质对话框组件
【发布时间】:2017-07-09 12:39:22
【问题描述】:

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

这里是要触发的html:

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

这里是 TS:

openDialog(slug){


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

  }

如何在打开时将 slug 传递给对话框以便我可以使用它? 例如

let dialogRef = this.dialog.open(DialogGitHost,slug);

【问题讨论】:

标签: angular angular-material2


【解决方案1】:

尝试像这样传递数据:

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

并在 DialogComponent 中使用以下命令重新获取数据:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 2019-12-14
    • 1970-01-01
    • 2018-07-15
    • 2018-01-14
    相关资源
    最近更新 更多