【问题标题】:modal dialog when the app load应用加载时的模态对话框
【发布时间】:2017-05-05 07:23:37
【问题描述】:

我有一些关于模态对话框的问题:

1.如何将数据传递给模态并从模态返回数据?

2。我想在应用加载时显示模态对话框,按下按钮后会转到第二页。

假设这是我的对话。

@Component({
  selector: 'pizza-component',
  template: `
  <button type="button" (click)="openDialog()">Open dialog</button>
  `
})
export class PizzaComponent {

  constructor(public dialog: MdDialog) { }

  openDialog() {
    let config = new MdDialogConfig();
    let dialogRef:MdDialogRef<PizzaDialog> = this.dialog.open(PizzaDialog, config);

  }
}

@Component({
  selector: 'pizza-dialog',
  template: `
  <h2>{{name}}</h2>
  <p>Size: {{size}}</p>
  <button type="button" (click)="dialogRef.close('yes')">Yes</button>
  <button type="button" (click)="dialogRef.close('no')">No</button>
  `
})
export class PizzaDialog {
  name:string;
  size:string;
  constructor(public dialogRef: MdDialogRef<PizzaDialog>) { }
}

【问题讨论】:

    标签: angular modal-dialog material-design angular-material


    【解决方案1】:

    我如何将数据传递给模态并从模态返回数据? - 有很多关于此的很棒的文档 (https://material.angular.io/components/component/dialog)。
    基本上,您可以通过设置组件实例将数据从父组件设置到对话框组件。您可以在关闭方法后通过对话框引用将对话框中的数据返回到父组件,如下所示:

    dialogRef.afterClosed().subscribe(result => {
      this.selectedOption = result;
    });
    

    我想在应用加载时显示模态对话框,按下按钮后会转到第二页。 - 你可以在对话框上调用 open 方法在 ngOnInit 生命周期钩子中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多