【发布时间】:2021-08-14 21:56:51
【问题描述】:
在我的 ngOninit 代码中,我调用了很多 API,因此它们需要一些时间 我在渲染这些细节时遇到了一些问题 所以我决定添加预加载器,因此我想在初始化所有数据之后执行我的 ngAfterContentInit() 方法,但在完成所有数据之前,ngAfterContentInit() 方法仍然令人兴奋
这是我的 ngoinit 方法
ngOnInit(): void {
this.prealoader = true;
console.log("init componant"+this.prealoader);
this.userservice.currentLoginUser.subscribe( (res: any) =>{
console.log(res);
this.data=res;
if(this.data){
this.getAllFriendsId();
}
if(this.data.user_info){
this.editProfile = this.fb.group({
'workplace':this.data.user_info.workplace ? this.data.user_info.workplace : '',
'highSchool':this.data.user_info.highSchool ? this.data.user_info.highSchool:'',
'university':this.data.user_info.university ?this.data.user_info.university:'' ,
'CoverPhoto':'',
'currentCity':this.data.user_info.currentCity ? this.data.user_info.currentCity:'',
'homeTown':this.data.user_info.homeTown ?this.data.user_info.homeTown:'',
'relation':this.data.user_info.relation?this.data.user_info.relation:'',
'user_id':this.data.id
});
}else{
this.editProfile = this.fb.group({
'workplace':'',
'highSchool':'',
'university':'' ,
'CoverPhoto':'',
'currentCity':'',
'homeTown':'',
'relation':'',
'user_id':this.data.id
});
}
});
console.log("no"+this.CoverPhoto);
this.oninitgetdata();
}
这是我的 ngAfterContentInit() 方法
ngAfterContentInit(){
this.prealoader=false;
console.log("after init componant"+this.prealoader);
}
请帮助我如何做到这一点
【问题讨论】: