Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ngx-toastr with SetInterval in ngOnInit Fires Error #1021

Open
oguzhannb opened this issue Jul 27, 2024 · 0 comments
Open

Using ngx-toastr with SetInterval in ngOnInit Fires Error #1021

oguzhannb opened this issue Jul 27, 2024 · 0 comments

Comments

@oguzhannb
Copy link

Hi ,
Im trying to use ngx-toastr basically in ngOnInıt like below code.If i use same code in button click event it works perfectly with no error.Is it related with isStable control i use it for using the setInterval otherwise cant use setInterval without stable angular.What causes this and how can i fix this ?

app.component.ts:
ngOnInit(): void {
this.applicationRef.isStable.pipe(first((isStable) => isStable)).subscribe(() => {
console.log("stable");
var timeoutObj=setInterval(() => {
this.progressValue+=1;
console.log(this.progressValue)
this.changeDetectorRef.detectChanges();
if(this.progressValue === 100){
this.toastr.success("Top right");
clearInterval(timeoutObj);

   }
   },50);
});

}

Error:RuntimeError: NG0205: Injector has already been destroyed.
at R3Injector.assertNotDestroyed (C:\Users...\OneDrive\Desktop\angular\progressSample.angular\cache\18.1.2\vite\deps_ssr\chunk-VEVNQUEW.js:4393:13)
at R3Injector.get (C:\Users...\OneDrive\Desktop\angular\progressSample.angular\cache\18.1.2\vite\deps_ssr\chunk-VEVNQUEW.js:4300:10)
at Object.definition.getStandaloneInjector (C:\Users...\OneDrive\Desktop\angular\progressSample.angular\cache\18.1.2\vite\deps_ssr\chunk-VEVNQUEW.js:18887:27)
at ComponentFactory.create (C:\Users...\OneDrive\Desktop\angular\progressSample.angular\cache\18.1.2\vite\deps_ssr\chunk-VEVNQUEW.js:12693:53)
at DomPortalHost.attachComponentPortal (C:\Users...\OneDrive\Desktop\angular\progressSample.angular\cache\18.1.2\vite\deps_ssr\ngx-toastr.js:487:37)
at DomPortalHost.attach (C:\Users...\OneDrive\Desktop\angular\progressSample.angular\cache\18.1.2\vite\deps_ssr\ngx-toastr.js:313:17)
at OverlayRef.attach (C:\Users...\OneDrive\Desktop\angular\progressSample.angular\cache\18.1.2\vite\deps_ssr\ngx-toastr.js:560:29)
at _ToastrService._buildNotification (C:\Users...\OneDrive\Desktop\angular\progressSample.angular\cache\18.1.2\vite\deps_ssr\ngx-toastr.js:804:31)
at _ToastrService._preBuildNotification (C:\Users...\OneDrive\Desktop\angular\progressSample.angular\cache\18.1.2\vite\deps_ssr\ngx-toastr.js:765:17)
at _ToastrService.success (C:\Users...\OneDrive\Desktop\angular\progressSample.angular\cache\18.1.2\vite\deps_ssr\ngx-toastr.js:669:17) {
code: 205

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant