Questions tagged [lifecycle-hook]
42 questions
35
votes
2 answers
How to implement multiple lifecycle hooks for an Angular2 component?
I know that when defining components in Angular2 you have multiple types of lifecycle hooks that you can implement such as OnDestroy, NgOnInit, etc.
In every sample piece of code I've seen online about using these hooks, I only ever see them being…

SemperCallide
- 1,950
- 6
- 26
- 42
11
votes
5 answers
Invoke a script on EC2 termination
I have to take certain actions during AWS autoscaling scale-in event.The ec2 instance should be able to save some logs and reports to S3 bucket. This can take anywhere between 5 to 15 mins.
I already have a script that gets called on termination:
ln…

rahul gupta
- 238
- 1
- 4
- 11
6
votes
1 answer
{{ call() }} in template executes the method block multiple times?
Here the statements in test method is called multiple times. Why is this happening? Is DOM is recreated by AngularJS2 multiple times?
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
Method Call…

Prajeet Shrestha
- 7,978
- 3
- 34
- 63
5
votes
4 answers
Angular 4 : Difference between ngDoCheck vs ngAfterViewChecked
In Angular 2+, ngDoCheck and ngAfterViewChecked seems to perform same function.
ngDoCheck is said to be called whenever change detection is triggered. Now this change detection will be triggered with change in View. As per docs, ngAfterViewChecked…

harsrawa
- 422
- 5
- 18
4
votes
2 answers
How to use OnDestroy properly
I've seen a lot of question related to ngOnDestroy. I think many of us not using it correctly or not using it at all. I just want to see a list of tips how can you properly use ngOnDestroy and what should we do in the best scenario to prevent memory…

Jánosi-Borsos Róbert
- 500
- 6
- 17
3
votes
1 answer
How do I run a function on ngOnInit() only once and not again upon returning back from another routerLink?
HomeComponent
ngOnInit()
{
console.log('loaded');
this.retrieveData();
}
retrieveData()
{
// this.dataService.getData().subscribe(...);
}
I am retrieving data when the component loads. When the user clicks on another routerLink, for…

anonym
- 4,460
- 12
- 45
- 75
2
votes
0 answers
Behavior of the custom-element-upgrade process when the constructor throws an exception - lifecycle callbacks don't fire
Chrome mobile.
I have observed a bit confusing behavior when upgrading element which's constructor (or field initializer) throws an exception.
const testline=document.querySelector("#testline");
const…

Murphy
- 19
- 3
2
votes
2 answers
React get new data in componentDidUpdate
I have a component which receives a list of news from two or three APIs. the first time the component renders, the apis are called and data is rendered in componentDidMount
something like this:
componentDidMount() {
…

Amir Shahbabaie
- 1,352
- 2
- 14
- 33
2
votes
2 answers
OnChanges does not trigger on partial object change
I am having issues while triggerin Angular(6)'s onChanges life cycle hooks. While emitting parameters from a compontent to a directive I want to hook on the changes.
The trigger works perfectly on one-dimensional variables, while objects are not…

Michael W. Czechowski
- 3,366
- 2
- 23
- 50
2
votes
3 answers
Angular (2+) : how can i know from parent component when all child-components were initialized?
is there a lifecycle hook so-called "ngAfterAllChildrenInit" because ngAfterViewInit is called before ngOninit of the children,
I am trying to avoid hacking with setTimeOut or emitting events from all the children and collecting them and then do…

Shaul Naim
- 246
- 3
- 15
2
votes
2 answers
Trigger one component method after other component fully load
I have two components, both are loading in my like this:
and index.html
Is there a way to…

esquarial
- 277
- 1
- 4
- 15
2
votes
2 answers
How to get real attr values in didReceiveAttrs hook, if it's a mutable cell
Please see below sample code.
Given I have a component my-text-box
my-text-box.hbs
{{my-text-box value=modelName}}
I want to observe the changes of value property via didReceiveAttrs hook instead of observers for better…

shijistar
- 111
- 4
1
vote
0 answers
Cannot scrollIntoView in vue onMounted hook
I have a msgHTMLElement that is reactive based on an array ref. The scrollIntoView works as expected when watching the ref.value. As the array is updated, the HTML element representing the data updates and scrolls to the bottom as expected . .
const…

learnvst
- 15,455
- 16
- 74
- 121
1
vote
1 answer
Vue lifecycle hook race condition
I have a question regarding the Vue lifecycle hooks. I have some method that I want to call first in a hook, but another method is calling before.
The desired method is loadData() that calls from beforeMount. This method is responsible for API…

Evgeny
- 193
- 2
- 13
1
vote
1 answer
Why get undefined after the render of the DOM in the following case?
It's a demo in the article 11 Vue.js Lifecycle Hooks
I am confused why I can not get the DOM in mounted after 3 seconds, while can get the result as respected if console.log immediately.

Zia
- 21
- 4