Questions tagged [angular-component-life-cycle]
28 questions
1020
votes
29 answers
Angular/RxJS When should I unsubscribe from `Subscription`
When should I store the Subscription instances and invoke unsubscribe() during the ngOnDestroy life cycle and when can I simply ignore them?
Saving all subscriptions introduces a lot of mess into component code.
HTTP Client Guide ignore…

Sergey Tihon
- 12,071
- 4
- 23
- 29
6
votes
1 answer
What happen if i use ngOnInit method without implementing OnInit interface
Can anyone please tell me what will happen if I don't implement onInit interface and still using ngOnInit component lifecycle inside a component?
Since I used ngOnInit lifecycle hook without implementing an interface and it's worked for me the same.…

Anshita Singh
- 1,583
- 1
- 17
- 40
4
votes
2 answers
Angular set component styleUrls dynamically
I am using the latest version of angualar 5.0 in the new project. And i am new to this framework and would appreciate some help from the angular developers.
I would like to set the styleUrls property with class level variable at the runtime…

Karan
- 3,265
- 9
- 54
- 82
3
votes
3 answers
Why is change detection called twice?
I have a simple test-component with no logic.
I render this component.
Why is the DoCheck hook called twice?
So far I understand, DoCheck is called for every change detection.
But there is no change.
I just render the component and DoCheck is…

Catweazle
- 105
- 1
- 8
2
votes
3 answers
How can I load angular components in a page in sequence?
My problem scenario is as follows,
I have a page with a large form (+100 inputs). These inputs are divided into sections and those sections are developed as different components (for reusing purposes). So the general layout of the page is something…

charith.arumapperuma
- 665
- 1
- 7
- 21
2
votes
2 answers
Angular ngFor lifecycle
I'm using *ngFor to iterate some data like this:
{{d}}
Everything is fine and I got the result as expected:
1
2
3
Then, I wondered if I use a function instead of…
Muhammad Vakili
- 708
- 4
- 19
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…

Jay Bansod
- 29
- 4
1
vote
1 answer
Change Selector of Component coming from Library
Context
I am working on a user interface library - which in itself is consuming another Angular Library which provides own components (for the sake of the example let's assume it's the Angular Material Library. Some of the components provided are…

Maximilian C.
- 967
- 5
- 22
1
vote
1 answer
Can we implement logic for all the Angular component ngAfterViewInit method?
All, I am looking a generic way to implement ngAfterViewInit method for all the components in a big web application.
The reason is we need to track each page's loading time, so in order to do this, I need to put checking solution into…

user3006967
- 3,291
- 10
- 47
- 72
1
vote
2 answers
Real UseCases for ngDoCheck (Angular9)
I am a beginner in Angular & learning by myself and i have stucked in ngDoCheck life cycle method
According to Documentation:
Detect and act upon changes that Angular can't or won't detect on its own.
Parent Component:
user={
…

Ram
- 117
- 1
- 1
- 10
1
vote
1 answer
Angular child component not updating when the parent view updates
So I have some simple synchronous local data shared amongst parent views and that all functions just fine, when the local data changes all the parent views that use it update and reflect correctly.
However when I began splitting my growing project…

June
- 383
- 3
- 12
1
vote
1 answer
child with input binding angular 5 calling multiple times
I'm making a website in angular 5. I'm using input binding in one of the components.
For 'recommendedHotels' I'm getting…

syed hussain haider zaidi
- 107
- 2
- 5
0
votes
2 answers
Why the content is not displaying when ng-content is used?
We know that the app-root component selector is used in the index.html file. So I placed some content between the selector. So to access the content I used ng-content inside the app-root HTML file. but the content is not displayed in the browser. It…

dev sathwik
- 13
- 4
0
votes
2 answers
Cannot read properties of this object values of parent component to child component function in angular
I'm calling a function declared in parent component in the child component in the form of callback.
Parent Component
translation-editor.component.ts
export class TranslationEditorComponent implements OnInit {
textGuid: string =…

NeonH
- 65
- 2
- 11
0
votes
2 answers
Destroyed component's properties are accessible via subscription - how?
I have this example stackblitz where I set an "id" for a component which you can create and destroy via a checkbox. Each time you create a new instance of the component, it is given an incremented id.
In each component, there is an interval which…

Caleb Bertrand
- 410
- 5
- 15