I have 6 methods, where they're called several times around the app:
Here are few of them:
getLegal(){
let status = 'Active';
this.auth.getLegalIndividual(status).subscribe(
(data)=>{
this.legalData = data;
},
(error)=>{
console.log(error);
}
)
}
getSituation(){
let status = 'Active';
this.auth.getSituationIndividual(status).subscribe(
(data)=>{
this.situationData = data;
},
(error)=>{
console.log(error);
}
)
}
Each time they're called the data is saved in an object and used.
I want to run them only one single time at the load of the app in app.component.ts
and save the returned results into global objects and it will accessed by components where it should be used.
ngOnInit(){
this.getLegal();
this.getSituation();
}
Auth Script:
getSituation(status) {
let httpParam = new HttpParams().set('type', 'unit')
.set('status', status);
return this.http.post(this.globalVar.GetSituationUrl, httpParam);
}
Where this.globalVar.GetSituationUrl
is the url to the php script.
Is method going to slow down the load of the app ? And on changing routes, the ngOnInit()
going to run again?
I am slightly new to angular and few things are obscure.