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

How to debug significant time difference between constructor and ngOnInit()

I have an angular app, where i open an angular material dialog. The opening of the dialog is triggered from two different places in my code. When I trigger it from place A, the dialog component loads as fast as expected. When I trigger it from place…
Philipp
  • 378
  • 1
  • 2
  • 12
0
votes
0 answers

How to use any type of property in a component on ngOnchanges

How to use any type of property in a component on ngOnchanges without @input property. I can not use Rxjs for this situation. It is not a child component so i have no @input property. Please see the following example. import { Component, OnInit,…
0
votes
1 answer

Effect of ngIf on ngAterViewInit

I am emitting an event in ngAfterViewInit lifecycle hook, and listening to that event in another component using ComponentRef. It works well until I use ngIf on the parent component. So, what is this effect of ngIf on Angular life cycle hooks? For…
0
votes
0 answers

ngOnchanges is triggered and geting the currentValue(it is an object) but can't access the value inside the object

dragAndUpload.ts export class DragAndUploadComponent implements OnInit { @Input() filesData: any; ngOnChanges(changes: SimpleChanges): void { console.log(changes.filesData.currentValue); …
0
votes
2 answers

Angular Lifecycle hook when there is a change on service

I have a service - let´s call ServiceA, which makes multiple HTTP calls and I want to retrieve info when everything is calculated.For that I have a boolean variable - isEverythingProcessed, when that happens. On my component - let´s call…
Goldbones
  • 1,407
  • 3
  • 21
  • 55
0
votes
0 answers

createEmbeddedView into content projection after ngAfterViewInit

I have a setup in this parent.component where some complicated dynamic templates are resolved within some named ng-template elements. I then want to insert these in a dynamic order on the page, which I do in the ngAfterViewInit using…
MattTreichel
  • 1,418
  • 3
  • 18
  • 35
0
votes
2 answers

Angular manually set @Input value is still overwritten with the same value in ngOnChanges

I have a parent component employees.component.ts and a child component employee.component.ts. The parent's template is divided into two parts - 20% of the width is a PrimeNG tree component (its nodes represent different employees) and the rest is…
syydi
  • 119
  • 2
  • 13
0
votes
1 answer

Why does Angular Oninit only call service when navigated away from page

Using Angular router, when user navigates to a certain page of the SPA, I want to check if user is authenticated, by calling a service in ngOninit in order to display the sign-in or sign-out button as the case may be. But ngOninit doesn't fire, and…
0
votes
3 answers

How to run code after Obsevable AND rendering finished in Angular 11?

In my Angular 11 project I have an Observable what changes the view and take some times while it's rendering. Something like this: export class MyComponent implements OnInit { myObservable = of([1, 2, 3]); constructor() { } ngOnInit(): void…
netdjw
  • 5,419
  • 21
  • 88
  • 162
0
votes
2 answers

How to use await in angular lifecycle hooks?

stackblitz code i am working on a angular application to export PDF but can't see the data values in exported PDF. my approach: i have 2 components (login,home) ,created a button(export) in login component and which will navigate the user to home…
sravan ganji
  • 4,774
  • 3
  • 25
  • 37
0
votes
1 answer

Can't Update child components property in angular

I have one functionality for filter data. when I enter some values in filter popup it showing result successfully. then I add those data in local storage (as I need to keep those data on back link) and I am redirecting to another page, when I press…
0
votes
0 answers

How to reuse instantiated component in a Angular Material dialog?

We are trying to create a component that has two "view states" - state A is just as usual in the document flow (kinf of like a preview/thumbnail). State b should be a enlarged version of it (modal). We had no problem to create a component and use it…
sandrooco
  • 8,016
  • 9
  • 48
  • 86
0
votes
1 answer

ngOnInit() is called twice and getting two API responses

app.component.ts export class AppComponent implements OnInit{ title = "quogen"; response : Response[]; constructor (private dataService : DataService) { } ngOnInit () { console.log("calling init"); return…
0
votes
0 answers

Angular: count class instances, display on page

Big noob, first question. Course project "quiz app" displays question after question, and results at the end. I want to add a count of correct answers, by counting the number of elements with class "correct" on the results page. Please let me know…
Chris
  • 1
0
votes
1 answer

On change of input field in step 1 reset values in step 2 of mat stepper

I am using Angular material stepper for my application. Each step has individual components. parent.html:
ani
  • 446
  • 1
  • 9
  • 31