admin管理员组文章数量:1430078
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);
});
}
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);
});
}
Share
Improve this question
asked Jan 29, 2019 at 6:57
HarryHarry
1332 silver badges11 bronze badges
2
- Can you show me the declaration of this.tailor? – officialMKL Commented Jan 29, 2019 at 7:00
-
1
You have declared
trailor : any[]
, which is an array, So you should be accessing it likethis.tailor[0].name
– Amit Chigadani Commented Jan 29, 2019 at 7:06
1 Answer
Reset to default 5You 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
版权声明:本文标题:javascript - error showing in my .ts code > [ts] Property 'name' does not exist on type 'any[]&am 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745495723a2660797.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论