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
2 answers

Dynamic creation class field on ngOnInit() in Angular

I try to dynamic create variables in class to store values and use it in ngModel and other placese. I know, that I can assign value to variables in ngOnInit() like this export class Component implements OnInit{ name: string; ngOnInit(){ …
Denis Savenko
  • 829
  • 1
  • 13
  • 29
0
votes
3 answers

How to call a function eveytime a component is opened?

I have an app which connects to a firebase database and download all items then the items are displayed in tables like this: This table is only shown if Im logged in but as soon as I move to another component and return to the one with the tables,…
0
votes
2 answers

Angular 5 - unable to print rest json data by ngFor using ngOnIt

I am trying to print the simple rest consumed json data in my HTML's select's options. I've done it many times but i can't figure out what i am doing wrong here. I want to use the ngOnIt beccause i have to load my countries and states before…
Abhishek Chokra
  • 1,381
  • 2
  • 9
  • 17
0
votes
1 answer

Angular value coming to Child Component template but coming as undefined in ngOnInit

When I pass the value to child component values coming in template but not showing in ngOnInit of child component parent Component
prospectId {{prospectId}}
Mohammad Fareed
  • 1,927
  • 6
  • 26
  • 59
0
votes
2 answers

What is the best place to put a JavaScript listening function in Angular component?

TL;DR: I am rendering a BioDigital HumanAPI anatomical model in my Angular 5 app within an iFrame. I instantiate API object using: this.human = new HumanAPI(iFrameSrc); There's an API function human.on(...) that can be used to register click events…
Uzair A.
  • 1,586
  • 2
  • 14
  • 30
0
votes
3 answers

cannot access my json response data outside the ngOnInit() in my Angular 4.x app

I have an Angular 4.x app with a http request that is getting sent and I am getting back valid json from the endpoint (I can see this in the initial console.log) - the problem is I cannot see this data outside on the ngOnInit() just below where I…
Zabs
  • 13,852
  • 45
  • 173
  • 297
0
votes
2 answers

Angular ngOnInit common for all pages

Is there a way to setup common ngOnInit() to be executed on every single page in Angular application? Instead of writing in each and every page: import { AppComponent } from '../app.component'; constructor( private app: AppComponent)…
Dalibor
  • 1,430
  • 18
  • 42
0
votes
3 answers

Angular 2, can't get data after subscribe in ngOnInit

I have a problem, maybe I don't understand how to do but when I try to catch data from an HttpRequest during angular ngOnInit, my console.log return me an "undefined" value. The thing is that when I use this value in my template view it works…
Valentin Ferey
  • 43
  • 2
  • 10
0
votes
0 answers

ngFor firing before ngOnInit Http Request finished

I have a parent component with a list of objects and the child component is the detailed view of whatever object is selected from that list. I am putting the objects uuid into a url param and then doing an Http Get request with that uuid when the…
Brian Stanley
  • 2,078
  • 5
  • 24
  • 43
0
votes
2 answers

Angular 2 Dashboard application web api call at initialization

I have a dashboard application written in angular 2. I am using api call for the the data. After retrieving the data I render them in the graph. As the demo link below. When I make a api call from ngOnInit() method of dashboardcomponent I get null…
tksdotnet1
  • 81
  • 6
0
votes
1 answer

How to reload a view after router.navigate in Angular 4?

I have a switch to shop function which is controlled by a header component and displays a dashboard for that venue. In that header component, I navigate to dashboard route, even if I already in that route. this.router.navigate(['/venues',…
Burak
  • 5,706
  • 20
  • 70
  • 110
0
votes
2 answers

ngOnInit called in the middle of component lifetime

I having some issues with text.component (selector app-text) initialising in the middle of the app life time (not just when I create it). This is app.component.html:
sanjihan
  • 5,592
  • 11
  • 54
  • 119
0
votes
1 answer

AngularJS NgOnInIt method losing data on the second visit to my component using router-link

I have a component called edit-scrim and inside my component i have 2 arrays of type model "Team", i am using some methods from a service i imported into the component to assign values to the array. On my first visit to the page the arrays are being…
0
votes
3 answers

Pass ID(Index) to onEditDetail() Parameters

How can i pass the value index or id to EditDetail() parameters. I want it to be put inside the parenthesis of onEditDetail() once i click the onEditDetail() in html ngOnInit() { this.route.params .subscribe((params: Params) => { this.id…
Joseph
  • 7,042
  • 23
  • 83
  • 181
0
votes
1 answer

Angular 4 - Get und Set ng-model

I am trying to get and set a boolean to 'checkvalue'. I want beforehand to call a function isItTrue to set the variable 'checkvalue'. If the box is (un)checked/ and I check it, it should call a function doSomething(). I was experimenting with…
stefPan
  • 17
  • 7