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

Component initialization by ngIf does not trigger ngOnInit

I have a parent component with some childs that get rendered based on ngIf evaluation. I'm on Angular 8.1.3 The parent component import { ActivatedRoute } from '@angular/router'; import {FirstStageViewComponent} from…
4javier
  • 481
  • 2
  • 7
  • 22
0
votes
4 answers

Service class functions return undefined when i use it inside other components in Agular

I am using Angular 8. I have created a function called getUserInfo() in a service class which returns informations about the user using the cloud service Firestore. The problem is that when I show the result in the service class, it is defined and…
Shakar Bakr
  • 57
  • 1
  • 10
0
votes
0 answers

Ionic form calls ngOnInit multiple times

I have a form that displays existing data from Firestore and then upon on change the data is updated. The problem is that the ngOnInit seems to being called multiple times, then the saveInspectionChanges() function is called. I am not sure why these…
0
votes
1 answer

ngoninit not working on dynamically component

I tried to created dynamically component for reporting, which is i got the tutorial from this link : https://angular.io/guide/dynamic-component-loader Dynamic component is already load, but ngOnInit is not working, i had explorer many way such as…
Hansen
  • 650
  • 1
  • 11
  • 32
0
votes
0 answers

Merge two observable in ngAfterViewInit()

This bug is related with this.events$ initialized in ngOnInit() This question is very similar to others but still slightly different when it comes to execution time. I have simple zip to merge two observable like:…
0
votes
0 answers

The component inside ng-content is instantiated twice

I am using Angular 4 and I have a component 'X' which is basically a collapse-expand component. It wraps whatever is provided to it and collapse and expand it on clicking. It looks similar to below one.
// some X related DOM here …
0
votes
1 answer

Switching between two subscriptions in the ngOnInit() method

I have a page where I am populating invoices into a grid. In the grid there is an option to view the payments for a particular invoice. The button switches the user from the invoices page to the payments page where it then filters all the payments…
0
votes
2 answers

undefined value return on ongonit for function parameter

have two functions which , first function returns the result which stored in a variable, the same returned result variable passed as parameter in second function to hit the service. as explained code below , the two functions are invoked on ongonit…
vijay munnangi
  • 43
  • 1
  • 4
  • 13
0
votes
1 answer

How can you subscribe twice on ngOnInit?

I have to subscribe twice on ngOnInit() in my component.ts but it seems that you can only subscribe once. The second subscription is ignored. How can I solve that? I tested it and changed the function and always the first subscription works the…
Anna Marie
  • 91
  • 2
  • 11
0
votes
1 answer

highcharts error -13 while the charts has been rendered

I am using highcharts in my angular application. Even though my charts are rendering on load, i am still getting highcharts #error-13 in my console. I am calling my render chart method inside ngOnInit lifecycle hook. I also added the check to…
Thushara
  • 57
  • 5
0
votes
5 answers

Initializing properties inside ngOnInit scope

I'm using ngOnInit in order to get a response from a Loopback API call. The property I initialize inside this scope can't be used outside the subscribe scope. I know this is a simple answer but I'm just not seeing it private siteData: Kiosk; …
Nakatax
  • 13
  • 6
0
votes
1 answer

Hide table using ngOnInit

I need to hide a particular column in the HTML table when the page loads. I used ngOnInit() to hide the column. But it works only for the and not for . But, when I used in click function it works for both and . How can I achieve…
suganya
  • 21
  • 4
0
votes
1 answer

Service subscription in ngOnInit gets called once and does not stay populated on route change

Just to clarify. This angular app is populating the data to the view but when I navigate from one component to the other the ngOnInit lifecycle hook does not seem to get invoked thus meaning that the list on the view remains empty. When i hit f5…
Metrophobe
  • 83
  • 1
  • 9
0
votes
1 answer

call method in ngOnInit

I am trying to call a method if a cookie is detected on page load. If detected, it should load my apps dark theme. I'm using Angular 7 and 'ngx-cookie-service'. I can switch themes fine, but cannot figure out how to automatically switch theme when…
lckdwn
  • 45
  • 1
  • 9
0
votes
4 answers

How to Sum up the values of 5 diff columns as TOTAL using *ngONinit?

i am having an array of Product with fields name ID,Brand,Price,QtySold,Value where value=Price*qtySold and at the end i need to show Number of Items,Total quantity sold and total sales value @Component ({ selector: 'my-app', templateUrl:…
Aman Solanki
  • 63
  • 1
  • 9