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
0
votes
0 answers

Angular do something when element is visible

I want to call method when component is visible. Problem is that component is not visible but hook ngAfterViewInit is called anyway. What can I do to call it after component is visible. ngAfterViewInit(): void { methodToBeCalled(); }
Juraj Jakubov
  • 291
  • 4
  • 13
0
votes
2 answers

ngAfterViewInit not patching the form's values

I want to set the form's value with something that I have stored in the localStorage. The output of the console in the ngAfterViewInit() function shows a value existing for monthlyHoursName. The output for the values of the form is {}, i.e. an empty…
Spurious
  • 1,903
  • 5
  • 27
  • 53
0
votes
2 answers

Angular Component isn't displaying data dynamically fetched from http client calls

I have a component that displays some data collected from a Microsoft API. The resulting data (which is in the form of a custom interface we created), is returned and stored in an observable within that component. When iterating through the objects…
0
votes
1 answer

How can I call a specific public method of any component in Angular, like how `ngOnInit` works

In my project, I have many components. And I have an event handler. When a particular event occurs, I want to call a particular method inside the component by it's name (if it exists in any of the component). Please find the below…
0
votes
1 answer

How to wait for DOM to render

I have to wait for DOM to render before going into next functions. Here is the flow/lifecycle: Push into the Array: this.someFormArray.push((this.createForm({ name: 'Name' type: type, }))) Trigger functions that are trying to…
gerkane
  • 3
  • 4
0
votes
0 answers

What is the exact meaning of "Initializing component" and "displaying the data-bound properties" in Angular

Angular doc says for ngOnInit ; Initialize the directive/component after Angular first displays the data-bound properties and sets the directive/component's input properties. But what does exactly initializing mean ? Because When I create a…
0
votes
0 answers

Angular lifecycle hooks are not triggered when components in libraries are rendered from the app

I have few angular libraries which displays a set of components and its related logic resides in it. I have an angular app, in which I want to make use of the above libraries to display the components inside a container. For this to work, I have a…
0
votes
1 answer

Angular How to call method from child after parent component template changes

I have a parent component, it has a side menu and content. Inside the content, a child component is rendered using router-outlet. | menu | content | | | |---------------------------| | | | | child …
Raz-Dva
  • 35
  • 4
0
votes
2 answers

Why am I getting ExpressionChangedAfterItHasBeenCheckedError Error when it is called before View is Checked - Angular

This is my code home-component.ts export class HomeComponent implements OnChanges, OnInit, DoCheck, AfterContentInit, AfterContentChecked, AfterViewInit, AfterViewChecked { loading = false; constructor() { } ngOnChanges(changes:…
Lijin Durairaj
  • 4,910
  • 15
  • 52
  • 85
0
votes
1 answer

Angular update @Input() Object

I've got a GameStats Object of my self defined interface. If I change the value of a attribute the child component doesn't recognize it. I found solutions with ngOnChanges which doesn't get fired, and with ngDoCheck which still contains the old…
user17087006
0
votes
1 answer

Do we need afterViewInit lifecycle hook anymore in angular?

We know that the afterViewInit lifecycle hook gets triggered once when a component finally finishes the initialization of it's view. Thus if any component has to work with it's viewChild, this lifecycle hook get's it's relevance to be invoked inside…
0
votes
1 answer

Ionic 3 Lifecycle events happening out of order when navigating to different pages

When navigating from one page to another using nav.setRoot(page), why does the iOnViewWillLeave event handler of the current page capture the leaving event after the iOnViewDidLoad of the target page already executes? I need to unsubscribe from an…
0
votes
1 answer

Angular Component constructor loads twice when httpClient is called from Constructor

Angular constructor loads twice when httpClient functions are called from the same constructor. export class ViewOrderDetailsComponent { constructor( private activatedRoute: ActivatedRoute, …
0
votes
2 answers

Unable to show loader on screen between ngOnInit and ngAfterViewInit lifecycle hooks in Angular

I have an angular component which has some components on its template which take some time to load, As a result the control to ngAfterViewinit() lifecycle hook reaches after some time (~20s) after the component is initialized in ngOnInit(). I want…
Madhur Maurya
  • 1,016
  • 4
  • 19
  • 42
0
votes
1 answer

Can we set the input properties in ngAfterViewInit() instead of ngOnInIt()?

Generally ngOnInit() is used to set input properties when the component initialized. Similarly can we set the same input properties in ngAfterViewInit() instead of ngOnInit() ?. Can we implement all those operations on ngAfterViewInit() which we…