0

How to I pass to an angular2 material dialogue component?

Here is the html to trigger:

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

Here is the TS:

openDialog(slug){


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

  }

How do I pass slug to the dialog on open so I can use it? e.g.

let dialogRef = this.dialog.open(DialogGitHost,slug);
Tampa
  • 75,446
  • 119
  • 278
  • 425
  • 1
    See step8 from http://stackoverflow.com/questions/34205593/working-example-of-angular-2-0-material-mddialog-with-angular-2-0/40185852#40185852 – yurzui Feb 20 '17 at 09:45

1 Answers1

0

Try to pass data like this:

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

and in the DialogComponent you reseive the data with:

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