【问题标题】:in angular how to i can excute any function after excute my ngOnInit all functions在执行我的 ngOnInit 所有功能后,我如何执行任何功能
【发布时间】: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);

        }

请帮助我如何做到这一点

【问题讨论】:

    标签: angular angular10


    【解决方案1】:

    错误表示您尝试将null 值作为数组访问。因此,在您注销后$LoggedUserInfo 的情况下,这似乎是明智的,因为没有用户登录。为了防止在用户未登录时显示它,您可以使用auth blade derective

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      相关资源
      最近更新 更多