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