Home > database >  Return value from MatDialog without closing it
Return value from MatDialog without closing it

Time:04-28

I have this submit function that I use when the user submit a value in my MatDialog:

  submit() {
    this.dialogRef.close(this.name);
  }

I'd like to implement a new button in the dialog, 'Submit and new', so the user can add another object and submit it.

is there a way to return a value without actually closing the dialog so I can just reset his state no a new object?

CodePudding user response:

I don't think there is, but you have three solutions to do it :

  1. Use a service to do your logic instead of using .close : the logic will be done, and the dialog will be kept open.

  2. Close the dialog as currently done, do your logic, then open a new one.

  3. Put your logic payload into an array, and do so until the user is finished. Once he doesn't ask for "submit and new", but just "submit", call your logic for each element of the array.

The solution to be taken is up to you, but all 3 are acceptable, the changing factor is only the user experience.

(Just so you know, my personal solution would be the 3rd one)

  • Related