我有6种方法,它们在应用程序中被调用了好几次:
以下是其中的一些:
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);
}
)
}
每次调用它们时,数据被保存在一个对象中并被使用。
我只想在加载应用程序时运行一次
app.component.ts
并将返回的结果保存到全局对象中,组件将在应使用它的位置访问它。
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);
}
在哪里?
this.globalVar.GetSituationUrl
是php脚本的url。
方法会减慢应用程序的加载速度吗?在改变路线时,
ngOnInit()
又要跑了?
我对角度有点陌生,很少有东西是模糊的。