0

I just updated my angular 14 project to 15
In angular 14 I used the following code to fill dialog result

this.dialogRef.beforeClosed().subscribe(() => this.dialogRef.close(this.selectedRows));

It was OK and ran without any error, but after update to angular 15 the following error has occurred:

Maximum call stack size exceeded

It drops into infinity loop. I fix it with a boolean variable flag
Is it has a trick to have a same behavior like angular 14

Mohammad Dayyan
  • 21,578
  • 41
  • 164
  • 232
  • Calling Close from within a notification that it’s already closing seems odd to me. – 500 - Internal Server Error Dec 23 '22 at 10:24
  • I've run in to the same issue. Calling close in beforeClosed was an easy way to ensure that when the dialog is closed you were able to always send any necessary data regardless of how user closed it (background click, escape, close button). Was able to workaround this using pipe(take(1)). – cvb Apr 18 '23 at 15:05

1 Answers1

0

I'm not sure how this worked. You are creating an infinite loop. I'm sure this.dialogRef.close triggers beforeClosed() observable to emit a value, and you go get into an infinite loop.

Try: this.dialogRef.beforeClosed().pipe(take(1)).subscribe(() => this.dialogRef.close(this.selectedRows));

Would take(1) maybe work here?

O.MeeKoh
  • 1,976
  • 3
  • 24
  • 53
  • 1
    at first why you need call close inside the before close. during my experience when ever you faced with the code something like this the problem is your business logic. change your solution to solve your problem. – Mohammadreza Mohammadi Dec 23 '22 at 21:13