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 see fields in data (subscribe) in Angular

I want to choose the Objects that I want to put in the tasks array according to IdEmployee Im trying to display the content of data (in which there is the field "IdEmployee"), but when I display it, I can see : data.IdEmployee = undefined In the…
user123456
  • 171
  • 11
0
votes
0 answers

Why ngOnInit is recharge

why ngOnInit reloads after the data in firebase is modified Here is the line of code who make ngOnInit reload this.db.database.ref("clients/" + this.user.num + "/mots_cles"+motCleOrder).set(mot.toLowerCase());
tomtom
  • 11
  • 3
0
votes
1 answer

angular audio play on ngoninit not working

html code: ts code: let audioPlayer = document.getElementById('notification'); audioPlayer.muted = false; …
0
votes
3 answers

How to call ngOnit function of a component from another component in Angular

I have a component called "CreateBugsViewComponent" in this component I wat to use ngOnit function of my another component which is "ProjectBugsComponent" how can I do this the code for "CreateBugsViewComponent" is written below: import { HttpClient…
user10309793
0
votes
1 answer

How to pass parameters in Angular between pages

My Node.js backend returns the AWS Cognito tokens as JSON which are received in my Angular login Component. I wish to open my dashboard and pass the received tokens in my login.component.ts function I do: this.router.navigate(['/dashboard', {…
Kukula Mula
  • 1,788
  • 4
  • 19
  • 38
0
votes
1 answer

List of checkboxs keep initial state after changing page

Am using angular 9 and i have a list of checkboxes that need to be set true by default to list of some data. Upon unchecked of one those checkboxes it should display certain data. The problem i encountered is that when i have unchecked and try to…
snoopy
  • 105
  • 2
  • 10
0
votes
0 answers

ngSwitch is not destroying child components on switch change

I have a page a component that displays a list of items. When a user clicks on the item, a form should be displayed with the relevant data. Users also have the option of creating new items by selecting the relevant form. I have the following in the…
Richard
  • 121
  • 8
0
votes
1 answer

Access local var from ngOnInit from another function

I am new to Angular and TS. I am trying to access a local var that is in ngOnInit from outside it, but I don't know how to do it properly. I have a component called BlocklyComponent where I created the var. export class BlocklyComponent…
Sam
  • 19
  • 1
  • 3
0
votes
1 answer

ngOnInit() is called twice and getting two API responses

app.component.ts export class AppComponent implements OnInit{ title = "quogen"; response : Response[]; constructor (private dataService : DataService) { } ngOnInit () { console.log("calling init"); return…
0
votes
1 answer

Angular async ngOnInit instantiating a needed property

I have a property in an Angular component, instantiated through a service inside async ngOnInit: txtItems: TextItems[]; constructor(private textItemService: TextItemService) {} async ngOnInit() { // await on promise this.txtItems =…
Lou
  • 4,244
  • 3
  • 33
  • 72
0
votes
1 answer

Angular dependency injection and data initialization

I have a conceptual doubt that why do we use the constructor for injecting our services into the component and ngOnInit() life cycle hook to initialize all values. Of all the articles I've read, I understood that it's good practice to initialize…
0
votes
2 answers

where is the best place to capture params of routes in Angular

I have this layout Each time I select a project in sidenav component I must show the relational data of that selected project in the maincontent component The issue is that I have this in sidenav that is, each selected project goes to a new route,…
kintela
  • 1,283
  • 1
  • 14
  • 32
0
votes
2 answers

Code inside for loop don't work inside ngOnInt()

i have a problem on running for loop inside ng OnInit , i have a service which contains a methos getAllNews() which returning an arrya not an observable i am mentionig this to let you know that i can't use subscribe() method , so when i console log…
Ghost
  • 57
  • 1
  • 7
0
votes
1 answer

why does ngOnInit() execute multiple times for setInterval()?

I am very beginner in Angular. export class CountComponent implements OnInit { public no:number; constructor() { this.no=0; } public myfun():void{ this.no++; alert(this.no); } ngOnInit(): void { this.myfun(); …
Mohamed Arshad
  • 89
  • 1
  • 1
  • 6
0
votes
1 answer

Re-initializing a component or forcing it to run ngOnInit() again in Angular

I've got a table component in Angular that gets given different data depending on what the user has asked for and then populates a table. The table has gotten relatively complex and I need the entire component to essentially refresh when the user…
SkinnyBetas
  • 461
  • 1
  • 5
  • 27