Maximum call stack size exceeded error at dialogRef.beforeClosed after update to angular 15?

281 views Asked by At

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

1

There are 1 answers

1
O.MeeKoh On

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?