Questions tagged [ngoninit]

For questions about ngoninit, a lifecycle hook that is called after Angular has initialized all data-bound properties of a directive.

ngOnInit is a callback method that is invoked immediately after the default change detector has checked the directive's data-bound properties for the first time, and before any of the view or content children have been checked. It is invoked only once when the directive is instantiated to handle any additional initialization tasks.

See also, the documentation for the interface OnInit

230 questions
0
votes
4 answers

How the service method is working inside the ngOnInit() even ngOnInit() hook executed once?

This is the code inside of my Angular service.... export class DataService{ products = { 'productsList': [ {id: 101, name: 'Apple', qty: 2}, {id: 102, name: 'Mango', qty: 1}, {id:…
Aakash Giri
  • 53
  • 1
  • 8
0
votes
1 answer

How to retrieve a user identifier using ngOnInit with Angular 9

I'm new to Angular and I'm creating a forgot password link, which when the user interacts with it will send out an email to their email address with a unique password token in order so they can reset their password. I want to be able to recognize…
Robgit28
  • 268
  • 4
  • 18
0
votes
2 answers

Angular callHooks not triggered when refresh page

i had problem when i use F5 button or directive call url from address bar ngOnInit not called properly.. I'm using debugger to see what happen, and the problem is callHook not triggered after ngOnInit.. I'm using Angular 9.1.2 This is my…
lucky.omen
  • 15
  • 4
0
votes
1 answer

How do I refresh HTML table after performing POST request in ngOnInit()?

Upon visiting the component invoices.ts , it looks in the background for some updates and applies them to the existing ones. Otherwise when the user has no existing invoices, it will perform a POST request to create them. However, when the user…
Y_Lakdime
  • 825
  • 2
  • 15
  • 33
0
votes
2 answers

Angular - Value change of object not registering through change detection

i'm relatively new to learning Angular and have followed some instructions from a PluralSight demo on setting up a basic service, component and HTML page. When I run my service and debug, I can see that the service is successful in retrieving the…
0
votes
2 answers

Array is empty on angular typescript page

I'm filling my string 'Questions' with a function named 'getQuestionsWithInterviewId' but when I call it with the console.log in the ngOnInit and ngAfterContentInit methods it looks empty. import { Component, OnInit } from '@angular/core'; import {…
Furkan Doğanay
  • 93
  • 1
  • 10
0
votes
2 answers

Is ngOnInit too late to initialise an EventEmitter var inside a component in Angular?

I tried with the following child component class @Component({ selector: 'child', templateUrl: './child.component.html' }) export class Child implements OnInit { @Output() send: EventEmitter; public constructor(){} public ngOnInit()…
oomer
  • 159
  • 3
  • 13
0
votes
2 answers

Angular html component not rendering the local json data on loading the page

import { Store,STORES } from '../models/store'; export class StoreLocatorComponent implements OnInit { public Stores: any = []; constructor() { } ngOnInit(): void { this.Stores = STORES ; this.Stores.forEach(element => { …
ASR
  • 311
  • 2
  • 14
0
votes
0 answers

Angular 9 ngOninit of child component called twice

Using Angular 9, I have a child component where the ngOnInit function is called twice. The first time, some of the @Inputs are undefined and the second time, all @Inputs are properly initialized. The component renders on the second time. Here is…
0
votes
3 answers

this.results.rulesFired not getting defined

I have the following table rows
lmngn23
  • 511
  • 3
  • 15
0
votes
0 answers

Calling ngOnInit method from other component Angular 8

I have a question, I hope you can guide me, I am working in an angular application with Firestore and I need to call the ngOnInit method of a component from another component, the problem with this is that both components are integrated in different…
0
votes
1 answer

Should I initialise an Angular service in its constructor or in the ngOnInit method of the app.component?

I'm new to Angular. I have a service that needs to subscribe to a subject provided by another service. If this was a component, I would create the subscription in the ngOnInit method of the component. NgOnInit isn't called for Services, though. I…
0
votes
2 answers

How to use ngOninit with async data

I am calling a service method inside the ngOninit method and assign this service method's return value to a member variable. Later on, I want to use this variable value inside the ngOnInit again. But, I suppose due to synchronization issues, this…
zodiac645
  • 191
  • 1
  • 3
  • 14
0
votes
2 answers

Angular - Elements that are under ngIf* doesn't render when ngOnInit() is called

I notice that when I have some elements under ngIf*, on ngOnInit() those elements don't exists even when the condition is met. How can I "catch" the moment when an element that is under ngIf* is rendered (I need to call some function on it)
user3362334
  • 1,980
  • 3
  • 26
  • 58
0
votes
1 answer

Angular: data details page does not get updated with the new product

I'm not a front-end developer so please ... When I click on another account, I notice that the Account details page does not get updated with the new Account. Why? it seems like the ngOnInit life cycle hook is not invoked when the user navigates to…
AchillesVan
  • 4,156
  • 3
  • 35
  • 47