加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何将服务变量传递到Angular Material对话框?

发布时间:2020-12-17 08:01:25 所属栏目:安全 来源:网络整理
导读:对于 mdDialog,我如何传入变量?具体来说,如何将Angular服务注入对话框组件? 对于传递变量,您可以从MdDialog.open()方法调用中返回的MdDialogRef实例中获取对话框中打开的组件的实例. dialogRef = this.dialog.open(PizzaDialog,config)dialogRef.component
对于 mdDialog,我如何传入变量?具体来说,如何将Angular服务注入对话框组件?
对于传递变量,您可以从MdDialog.open()方法调用中返回的MdDialogRef实例中获取对话框中打开的组件的实例.
dialogRef = this.dialog.open(PizzaDialog,config)
dialogRef.componentInstance.<property_name>

来自github material2 docs的改良比萨饼

@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);
    dialogRef.componentInstance.name = "Ham and Pineapple";
    dialogRef.componentInstance.size = "Large";
  }
}

@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>) { }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读