user8956519
user8956519

Reputation:

How to pass data in dialog angular 4

I have created a dialog to save a name with random id, now I did another click button to open me another dialog, in that dialog name should be passed so I can change the name. The name is not always the same changes every time. I created an store with angular ngrx that is the reason that if I want to edit to trigger the name or to pass the name. I did some things but doesn't work. Here is a code that opens the dialog.

openprojecteditdialog() {
const dialogRef = this.dialog.open(ProjectEditDialogComponent, {
  disableClose: true,
});
dialogRef.componentInstance.newProjectName = 'project';  }

If you need some extra code let me know I will post!

Upvotes: 0

Views: 1627

Answers (1)

Raja Mohamed
Raja Mohamed

Reputation: 1026

In angular 4 , Data passing to modal from component is same as component to component communication. Parameter variable name and Injector variable name should be same. Check bellow

const dialogRef = this.dialog.open(ProjectEditDialogComponent, {
     genericObj : { 
                   disableClose: true,
                  }
});

genericObj is parameter variable name should be same as injector variable name in Dialog modal. check bellow code

@Inject(MAT_DIALOG_DATA) public genericObj : any) { }

here the injector variable name should be genericObj . I hope you done mistake here.

Upvotes: 1

Related Questions