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

Angular Redirection executes my method as well as NgOnInit. Why?

I am new with angular so bear with me. I am having issue with Angular Redirection.When I clear storage manually, code executes ngOnInit, prompts error,redirects to Login page (as expected), but when I try to do same thing using logout method my code…
0
votes
1 answer

ngOnInit() when called from another component does not refresh the component

Am having two components named AddPersons and PersonList. After adding a person in the AddPerson component, I am trying to refresh the PersonList component. For that I tried calling the ngOnInit() of PersonList component from AddPerson. I am getting…
0
votes
1 answer

gsap animation plays only once when I put it inside angular ngOnInit function

I have an angular 7 project and imported Gsap library. I want an animation to be played every time I navigate to a page so I've implemented the gsap animation inside ngOnInit, but the animation plays only for the first time I visit the page and in…
Ali Haghighi
  • 143
  • 3
  • 11
0
votes
2 answers

Angular : how to deal with Asynchronous issues?

I m struggling to deal with what I thing is asynchronous issue with Angular 6. here is an example. I just want to get into the 'if' and display the console log, but it never happens. getListOne and getListTwo call an Observable API and are well…
Jean
  • 601
  • 1
  • 10
  • 26
0
votes
2 answers

Delete empty row created by subscription to service on ngOnInit()

I have a Material Data table, which the user can fill and empty by himself. The data, which gets into the table gets triggered by a service, which I initialized in the table component with ngOnInit(). Code: ngOnInit() { …
Michael
  • 287
  • 1
  • 10
  • 17
0
votes
1 answer

using ngOnInit() method on Ionic page - whether we need to import OnInit and write Class implements OnInit?

This the code that is used to load a variable with data on the page, using ngOnInit method: However, I notice that even if we don't import the OnInit (line 1) and don't write implements OnInit (line 10), the method is still invoked. What is the…
variable
  • 8,262
  • 9
  • 95
  • 215
0
votes
0 answers

NgOnInit not invoked on a header component

I have an Angular application which uses 2 components called Header and Footer. The Header component contains a ngOnInit method : ngOnInit() { this.isAuthenticated = AppSession.isAuthenticated(); } However when I try to load a page this…
javshak
  • 179
  • 2
  • 15
0
votes
1 answer

Unable to change variable value inside ngOnInit()

I have a simple form with 2 text inputs and a leaflet map, once the user clicks on the map, I get the longitude and latitude of the location. I'm setting the map in the ngOnInit() funuction, and I have a global variable for the latitude that I want…
Mourad Riahi
  • 95
  • 2
  • 13
0
votes
1 answer

Why am I unable to get access to object that was set on ngOnInit

Ran into a few problems lately and wonder why I can't access an object, that was set in the ngOnInit function for later purposes, like in another function? I want to access and use this.appointmentDetailId in my cancelAppointment() function but it…
user2880072
0
votes
1 answer

Directive's onInit method is called many times when the parent element is hidden and shown again

In the above code snippet (Angular 2), I change the variable from true to false and hence the directive won't render and next when i try to set variable to true again, onInit is called from…
bngk
  • 59
  • 14
0
votes
0 answers

AngularJS 1.6 and $onInit-Hook

I'm trying to wrap my head around the change with AngularJS regarding the components' lifecycle hooks, especially $onInit(). I'm working with Todd Mottos Course, where he build a component which, in my opinion, should not work with 1.6, but it still…
Vortilion
  • 406
  • 2
  • 6
  • 24
0
votes
0 answers

bind value to input angular 4 after input loaded to DOM

I wrote the bind script ngAfterViewInit, still is binding to undefined, where to call after the input loaded to DOM HTML
Mohammad Fareed
  • 1,927
  • 6
  • 26
  • 59
0
votes
1 answer

What is the difference between Constructor and ngOnInit in Angular 5

I have a parent class and child class in Angular. When trying to create a constructor inside child class it throws some error: Constructors for derived classes must contain a 'super' call. It will be working if the code is added in ngOnInit…
Shaju Nr
  • 338
  • 3
  • 18
0
votes
4 answers

Fully load content before showing it with Angular 2

In an angular component I'm generating an image from a service http call, which then I want to display on the site. However it's taking longer for the image to generate than it takes the site to load. Thus I'm forced to refresh a few extra times to…
Anders Pedersen
  • 2,255
  • 4
  • 25
  • 49
0
votes
1 answer

Reference Error inside ngOnInit

I am receiving an error on in my console that says ERROR ReferenceError: sortedArr is not defined after I have defined it and sorted it. Here is my app.component.ts file: import { Component } from '@angular/core'; import { HttpClient, OnInit } from…
newman
  • 421
  • 2
  • 9
  • 25