简体   繁体   中英

Angular - TypeError: Cannot read properties of undefined (reading 'showSpinner')

When I try to execute this block of code this is what I get.

core.mjs:6485 ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'showSpinner')

 async ShowData() {
  if(this.loading) {
    return;
  }

 this.loading = true;
 this.detailApp.showSpinner('Show Spinner');
 try {
    this.form.valueChanges.pipe(
      distinctUntilChanged()
      ).subscribe(async changes =>{
        await this.LandComponent.getAllData(changes.textName).then(data =>{
      this.preview = data;
      this.activePageDataChunk = this.preview.slice(0,this.pageSize);

    }).catch(error =>{
      console.log(error)
    })
  });
  }
  catch(e) {
    console.error(e);
  }
  this.loading = false;
  this.detailApp.hideSpinner();
} 

// detailApp.ts

export interface detailApp {
showSpinner(text:string):void
}

您的代码中的问题是this.detailApp未在文件中的任何位置初始化,因此undefined

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM