简体   繁体   中英

error showing in my .ts code > [ts] Property 'name' does not exist on type 'any[]'

My coding working fine. data showing on page, but an error accruing in VSE editor

Like this

[ts] Property 'name' does not exist on type 'any[]'.

my .ts file code is here

ngOnInit() {
    const data = {
      tailor_id: this.edit_id,
      user: this.userToken
    };
    this.https.post<any>('api/tailor/details', data).subscribe(response => {
      this.tailor = response.tailor;
      this.editTailorForm.controls['name'].setValue(this.tailor.name);
      this.editTailorForm.controls['phone_number'].setValue(this.tailor.phone_number);
    });

  }

在此处输入图片说明

You have declared tailor: any[] , which is an array, So you should be accessing it like this.tailor[0].name .

If tailor is an object, then declare it as tailor: any

And access like this.tailor.name .

Note : It is always good practice to use proper type like class , interface or typed object like tailor : {name: string, phone_number: number} to group object properties instead of using any

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