Questions tagged [angular-lifecycle-hooks]

A component in Angular has a life-cycle, a number of different phases it goes through from birth to death. We can hook into those different phases to get some pretty fine grained control of our application.

To do this we add some specific methods to our component class which get called during each of these life-cycle phases, we call those methods hooks.

Reference

143 questions
3
votes
1 answer

What if I don't have to call a statement as many times as ngAfterContentChecked() and ngAfterViewChecked() call

`ngAfterContentChecked() { console.log("Content checked"); } ngAfterViewChecked(){ console.log("View checked"); }` I am working on a project in Angular. I need to call a block of statements two times in a page - 1. When I click on a…
Ayushi Jain
  • 342
  • 4
  • 13
3
votes
0 answers

What is the best practice to measure the performance of an Angular app?

I'm working on an Angular app and try to analyse the performance of this app. For this I am using Elasticsearch's Kibana and APM server. The APM server is already able to measure the time for the inital page load and routing changes, by mainly…
3
votes
1 answer

Angular not detecting changes in ngFor in a new window from a postMessage

Background: my main page opens up an external window (same origin) of another module within my project upon button click. I also set up a BroadcastChannel so that these two windows can now communicate. Now, if this window is already open & the user…
3
votes
1 answer

How to trigger ionViewWillLeave in Ionic 4 with route in tabs.router.module

Lifecycle hooks ionViewWillLeave / ionViewDidLeave are not triggered when placing all pages routes in TabsPageRoutingModule. We changed the routes from app-routing.module.ts to tabs.router.module.ts to get full view of the tabbar in the Ionic 4 app.…
Tomas Vancoillie
  • 3,463
  • 2
  • 29
  • 45
3
votes
3 answers

Ionic 4/Angular 7 lifecycle hooks called just one time per page

In ionic 3 there was lifecycle events like ionViewWillEnter and ionViewWillLeave. But in Ionic 4 this event must be replaced by Angular lifecycle events like ngOnInit and ngOnDestroy. In my application I need to realize some given operations when…
Natanael
  • 1,326
  • 5
  • 17
  • 34
2
votes
2 answers

ngOnDestroy while reloading page

I'm trying to understand and experiment with Angular lifecycle hooks. Regarding ngOnDestroy, in the official documentation it says: A lifecycle hook that is called when a directive, pipe, or service is destroyed. Use for any custom cleanup that…
Eranki
  • 750
  • 1
  • 11
  • 30
2
votes
1 answer

Ionic Angular router component caching issue

Currently, I am developing an Ionic 5 application with Angular 9 (Single page app) and I am having some issues regarding the routing/component caching (At least that is what I think) and would need a bit of help. I will try to explain my situation…
2
votes
1 answer

Angular 9 incorrect element height returned on ngAfterViewInit life hook

I am trying to get the height of header, on ngAfterViewInit life hook. Chrome says height is 172px(which is correct), but my code says height is 142px(sometime 140px). Headercomponent.ts import { Component, ElementRef, ViewChild, AfterViewInit} from…
Var
  • 217
  • 5
  • 16
2
votes
0 answers

How do I implement ngInit in Angular 8?

I am trying to implement [ngInit] in angular 8 code as said in this link ConvertingAngular1To2ngInit and it almost worked for me but the problem is it execute more than one time and in some case it go in infinite loop or almost infinite and it crash…
2
votes
1 answer

Is there a lifecycle hook that runs once after a components initialisation, but also after two-way-binding is loaded?

I am trying to select some text in an input field after a component is initialised. I know I can do this with a setTimeout(), but that feels a bit too hacky. Most hooks run before the input text is loaded by two-way binding. The others also run…
Rob Monhemius
  • 4,822
  • 2
  • 17
  • 49
2
votes
1 answer

Scrolling to bottom; scrollTop = scrollHeight running too early?

Live example: https://angular-txvcna.stackblitz.io/ (Code). I have a "chat" component and I want to get the div to scroll to the bottom each time a message is added. I'm adding a new message by pushing an item to an array…
noamyg
  • 2,747
  • 1
  • 23
  • 44
2
votes
0 answers

How to handle uriParam before ngAfterViewInit?

I try to pass information from one website to another. The two websites do not share the same url or server. I have the idea that the best way is to use the URL parameters (http://some.url?param=value). So if I'm not mistaken in the Angular life…
2
votes
1 answer

AngularJS pure ng-controller lifecycle hooks

Suppose a pure AngualrJS (1.6.x) controller declared using ng-controller directive (in contrary to a component controller). Does it have lifecycle hooks like $onInit or $onDestroy?
mpasko256
  • 811
  • 14
  • 30
1
vote
0 answers

Why ExpressionChangedAfterItHasBeenCheckedError is throwed only with @Input()?

I'm trying to deeply understand ExpressionChangedAfterItHasBeenCheckedError in Angular. I read a lot of materials but still I got some doubts when and why this error is thrown Usual explanation of that issue is : Angular throws an…
ruddnisrus
  • 187
  • 5
1
vote
1 answer

Unnecessary call of ngDoCheck() hook in Angular, why this happens?

Why does ngDoCheck() hook gets called when I focused out from an tag? Here I've add one tag in app.component.html with [(ngModel)]="text" associates to it. I can understand ngDoCheck() hook get's called whenever I type(update) in input…
1
2
3
9 10