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
1 answer

How to update view when/after using async ngOnInit?

I have this situation. I need to call 4 services to have all the information that a component needs. When this async context resolves, the view is already built (I don´t have a way to avoid that right now) How to update the view after ngOnInit…
0
votes
1 answer

Angular ngOnInit how to use subscribe result for another subscribe/backend call?

I have this ngOnInit. the first subscribe works well and brings the value. The second one calls the backend, get the response (a non-null object) but it´s not setting this.taxas with the reponse value (yes, the type is correct and I can see the…
0
votes
2 answers

Undefined varibale already declared whet getting data from api on ngOnInit

I'm trying to fetch data from nodeJS API with angular, I have a variable declared and I want to affect the response from server to it, here is my code : export class SondageSingleComponent implements OnInit, AfterViewInit { …
547n00n
  • 1,356
  • 6
  • 30
  • 55
0
votes
2 answers

Angular Material tab navigates to selected tab after ngOnInit

I want to to navigate to new tabs and show loading spinner until search component gets data from api to display. But tab navigates to selected item only after component has been loaded. Is there any way to change that? If not how can I fire code…
IamGrooot
  • 940
  • 1
  • 17
  • 44
0
votes
0 answers

ngOnInit not called after changing URL manually

I have two types of users in my app : ADMIN and USER I'm trying to secure the pages that only an admin can access, so I wrote this code to prevent a non-adming user from manually changing the URL to an Admin page: ngOnInit() { …
LA.
  • 143
  • 2
  • 14
0
votes
1 answer

passing dynamic data to nested components

i have a main page with a list of orders ('list-orders' component), every time i click an order i open an 'order-details' component via router-outlet. in the order-details component i have in the html a component selector ('app-list-products'), in…
guy
  • 111
  • 3
  • 9
0
votes
0 answers

Angular - ngAfterViewChecked execute code but only once

I am loading a carousel with web pages on it. I want to grab a parameter and turn to that carousel slide representing the desired page (like a deep link). We've all seen something like this... the desired page element is correctly initialized…
AppDreamer
  • 1,266
  • 3
  • 16
  • 34
0
votes
0 answers

Angular: ngOnInit don't load my function?

I need your help please I would like to load myFunction when my page is load with ngOnInit(). But it's don't work. . . myData: any = []; . . . ngOnInit() { this.myFunction(); } myFunction() { return this.restApi.getMydata().subscribe((data:…
Zako
  • 11
  • 5
0
votes
1 answer

Service initializing once but not a second time

I just found a bug in my app I've been playing with that seems to make no sense to me. Issue: I have two components on different MatTabs. Each is instantiating properly and being destroyed between tab changes. My Post service is returning an…
Timotronadon
  • 315
  • 1
  • 2
  • 15
0
votes
0 answers

ngOnInit not getting called when navigating to a page through button click but called when navigating directly to it in browser

I am having a problem in creating an ionic v4 app (actually migrating an old Ionic v1, Angular 1 app) wherein when I load a url directly in the browser the ngOnInit methods get called along with the constructors but when I navigate to that url…
0
votes
0 answers

Angular8: Run oninit or onchanges for components referenced in response text

I have MathJacks loaded and working when the text is put into a template. But I am retrieving a large body of text from the server. This text is in HTML as it is heavily parsed and setup on the server. (FYI I'm using the sanitizer on the returned…
LeosSire
  • 93
  • 3
  • 13
0
votes
1 answer

Angular ngOnChanges not called after ngOnDestroy of parent

I have a child component which accepts an input In the child component, I detect changes to the customModel input by doing: @Input() customModel: CustomModel; ngOnChanges(changes:…
0
votes
1 answer

Why does the container size setting not working on ngOnInit?

I use this commands in order to set the size of the container: ngOnInit() { this.innerWidth = document.getElementById("Cont").clientWidth; this.containerWidth = this.innerWidth; console.log("init"); } @HostListener('window:resize',…
user11903678
0
votes
0 answers

Angular 5 ngOnInit called more than once

I have component for choosing periods for some charts. It can be some absolute dates or some quick intervals (last 30 days and so on). Then if its less than 14 days you get data in 1 hour interval by default. If its more than 14 days you get 1 day…
Jeopardy
  • 13
  • 5
0
votes
0 answers

Angular: Specifying a route based on radio button selection

I'm using radio buttons to display 2 options to the user, and based on their selection, they are routed to one of two components (one for each radio button). Any advice/ links on how to route to the desired destination based on their radio…