Questions tagged [ngondestroy]

For questions about ngondestroy, a lifecycle hook from the Angular Framework that is called when a directive, pipe, or service is destroyed.

ngOnDestroy is a callback method that performs custom clean-up, invoked immediately after a directive, pipe, or service instance is destroyed and so, it is generally used for any custom cleanup that needs to occur when a (component, directive, or service) instance is destroyed.

See also, the documentation for the interface OnDestroy

15 questions
5
votes
3 answers

Redirect to logout link after closing the last tab

As per the requirement, I have to log out the user when he closes the last tab on a browser. ngOnInit() { let counter: any = this.cookieService.get('screenCounterCookie'); counter ? ++counter : (counter = '1'); …
Nibha
  • 271
  • 1
  • 7
2
votes
0 answers

Prevent navigation in ngDestroy angular

I want to prevent the user from navigating away from the current page if the form is dirty. While this works with CanDeactivate guard, the problem is when I try to move on to another child component of the same parent, without a route change. The…
2
votes
2 answers

Remove observable action is subscription is unsubscribed

I have a problem which I tought I can solve with a subscription: refresh$: Subscription; data$: Subscription; ngOnInit() { this.refresh = interval(1000).subscribe(() => { this.getData(); } ); } ngOnDestroy() { …
AlleXyS
  • 2,476
  • 2
  • 17
  • 37
1
vote
0 answers

NGRX effect stale R3Injector after destroying and reinitialising module

I am attempting to use module federation along with ngrx store & ngrx effects in my webapp which is all in working order for the most part. However, I wish to destroy my NgModuleRef when switching to another lazy loaded route. Hence if I have one…
1
vote
2 answers

Angular/RxJs - Calling next() on Observable in service after component was unsubscribe() cause ObjectUnsubscribedError

I have an Angular Service that defines a public Subject. Later under some condition, the service will call .next() on this Subject. In addition, I have an Angular component that .subscribe() to this Subject in it's ngOnInit() method, and call…
Gil Epshtain
  • 8,670
  • 7
  • 63
  • 89
1
vote
1 answer

Angular ngOnDestroy

I've been trying to set up a network plugin as a service on an app to tell whether there's internet or not. In my example I've set up two components: HOME component with the network listener implemented directly in it and TEST component that…
jjgl
  • 387
  • 1
  • 5
  • 10
1
vote
2 answers

Angular 2: Cannot find ngOnInit/ngOnDestroy

NOTE: I found the article cannot find OnInit in typescript during implementation but the code below is already importing OnInit/OnDestroy. All the examples I've found (e.g., Using Route Parameters) indicate adding the implements OnInit/OnDestroy…
AdvApp
  • 1,094
  • 1
  • 14
  • 27
0
votes
0 answers

NgOnDestroy not working if close multiple browser tabs at once

This code is correct work if user close one or two tabs of browser @HostListener('window:beforeunload') async ngOnDestroy() { if (this.myValueSub) { this.myValueSub.unsubscribe(); } await this.authService.logout(); } But…
JactDotNet
  • 21
  • 1
0
votes
1 answer

Does Ionic 5 call ngOnDestroy for Services and home page when app is closed

In my Ionic 5 project, I have ngOnDestroy() for the service classes to clean up data. I also have ngOnDestroy() on my Home page. When I do the following navigation from the Home page to Page A and back to the Home page the ngOnDestroy() for Page A…
Tapas Mukherjee
  • 2,088
  • 1
  • 27
  • 66
0
votes
1 answer

sciptprocessor increasing CPU usage in Angular 10 with changes to input stream. Also how to destroy it

Looking to free up CPU resources from a volume meter I have implemented on a device-access component route. This volume-meter component takes an existing stream set up in a parent component (device-access), using a WebRTC…
0
votes
0 answers

How to Destroy an Angular application?

I have an Angular application, it is an simple application with routing. I have to include my application as a part of another website, the website load the app into a modal after loading all dependencies via RequireJS. The opening of the app into a…
Zauker
  • 2,344
  • 3
  • 27
  • 36
0
votes
2 answers

Can ngOnDestroy() be triggered on condition? When selecting the checkboxes, it keeps remembering my previous selects even after the grid reload

I have these two grid. The bottom one is based on the top one: Each of the items in the lower grid is related to the Program Name and the Tool# selected from the top grid. In this picture the "Delete Tool Change" button is enable since I have…
E S
  • 105
  • 2
  • 8
0
votes
2 answers

Angular/Typescript - Get timestamp OnDestroy

I'm trying to get a timestamp for every time a page is accessed and another timestamp when the user leaves the page. I get the time Oninit, however 'OnDestroy' I get the same exact time when of when the page was accessed. entryTime =…
thelandog
  • 674
  • 1
  • 9
  • 25
0
votes
1 answer

Service initializing once but not a second time

I just found a bug in my app I've been playing with that seems to make no sense to me. Issue: I have two components on different MatTabs. Each is instantiating properly and being destroyed between tab changes. My Post service is returning an…
Timotronadon
  • 315
  • 1
  • 2
  • 15
0
votes
1 answer

Angular ngOnChanges not called after ngOnDestroy of parent

I have a child component which accepts an input In the child component, I detect changes to the customModel input by doing: @Input() customModel: CustomModel; ngOnChanges(changes:…