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

set md-select input from a service

I have a "service" in setting part of my app. I push data in Firebase. In another component i have form with "md-select" that read the same data. The problem is that I can not initialize the list. Coming out and going back into the component…
0
votes
1 answer

Run the function after other functions in $onInit are done

Inside my $onInit function I have two functions that fetch data. I use third function where I need the data from the first two. The logic that I do in third function is what will be rendered on the screen. How do I use callback in $onInit and make…
Igor-Vuk
  • 3,551
  • 7
  • 30
  • 65
0
votes
1 answer

Initialize Arrays dynamicaly in Angular2

I'm trying to initialise Arrays variables from another Array in Angular2. Let me explain in details. Once I load my page, I receive from my server an Arrays containing strings (let's call it initialArray). And I would like to initialise Arrays…
Antoine
  • 1
  • 1
  • 6
0
votes
1 answer

angular 2+ ngIf div not appearing except after clicking on page

I have Google maps on the home page and I'm trying to route the user to another page when closing the info window that appears on the map: // Google map info window code snippet from a @Directive infowindow.addListener('closeclick', () => { …
Sammy
  • 3,395
  • 7
  • 49
  • 95
0
votes
1 answer

ngOnInit() runs methos parallel?

In my Angular project I call the method ConnectToHueBridge() and listAllGoups() from ngOnInit(). It seems to me that both methods will be parallel executed. But I need to run first ConnectToHueBridge() and then listAllGoups(). How can I do that? var…
WeSt
  • 889
  • 5
  • 14
  • 32
0
votes
1 answer

Passed-in Values Not Available at Run-time of Function in Angular App

I realize there is something I'm missing in terms of how and specifically when the products of certain functions are available in JavaScript. In my Angular app, in order to get a user's initials, I am parsing data being returned from the API, and…
Rey
  • 1,393
  • 1
  • 15
  • 24
0
votes
0 answers

ngOnInit method called twice

I'm a little bit new in Angular: When I load my Angular application (Angular 4), a specific component's ngOnInit() method called even if it wasn't rendered. After I navigate my app to a route that renders this component, the ngOnInit() called again.…
Roland Rácz
  • 2,879
  • 3
  • 18
  • 44
0
votes
1 answer

Angular 2 - too many observables to subscribe in ngOnInit()

I have a huge model-driven form which it's fields may affect each other's behavior, For example: If value of field A changes, Value of field B should be obtained from server,Or if value of field C changes, Field D should be disabled & etc. In order…
soroush gholamzadeh
  • 2,616
  • 1
  • 22
  • 30
0
votes
2 answers

Angular2 load data from backend before view loads

I have written the service code like this to read from backend getData(): any { let headers = new Headers( { }); let options = new RequestOptions({ headers: headers }); return this.httpClient.get('https://link',…
Kokulan
  • 1,316
  • 3
  • 19
  • 35
0
votes
1 answer

Redirect on ngOnInit Angular 2

I'm trying to redirect my app when launching and it's not working. I'm just trying to use router.navigate in my ngOnInit() and it returns false. I tried to insert it in a setTimeout and then it works. If you have any idea it would be appreciated…
Julien Moreau
  • 151
  • 1
  • 4
  • 16
0
votes
2 answers

ngOnInit visibility of private member

I have the following Directive. From within ngOnInit, both this.word and this.components are "undefined". Could anyone explain me why? import { Directive , Input, Output, ViewContainerRef, ComponentRef, DynamicComponentLoader, EventEmitter, OnInit,…
Mikou
  • 579
  • 1
  • 8
  • 17
0
votes
1 answer

Passing Value to Functions From ngOnInit

I have a button that calls clip function. I need to pass values from ngOnInit to that function but i can't. I get undefined error for (for example) this.firstX. How can i pass values from ngOnInit to functions? export class AppAppComponent…
Crypto
  • 157
  • 12
-1
votes
4 answers

Angular NgOnInit executing method before another

I have an angular application where I am trying to get an array of sources for an image carousel. How I have it set up currently I have a "getUrls()" method to get the urls from the database like so http.service.ts: getUrls() { this.http …
-1
votes
1 answer

Route parameters - subscribe method

"Angular does not create the component if it is already present in the DOM. It reuses the component instance. This implies that the ngOnInit life cycle hook is not invoked when the user navigates to the component again." Based on this, I cannot…
-1
votes
2 answers

How to handle undefined when passing data with Input in Angular?

A component colled with passing value with Input(): The component looks like: @Component({ selector: 'app-available-modal', templateUrl: './available-modal.component.html', …
mr_blond
  • 1,586
  • 2
  • 20
  • 52
1 2 3
15
16