[英]Typescript thinks an array is an object
public handleDesiredCityChange(place: any) { this.intPlaces.push(place.formatted_address); }
<div> <input ngx-google-places-autocomplete [options]='options' #placesRef="ngx-places" (onAddressChange)="handleDesiredCityChange($event)"/> </div>
I declared an array 我宣布了一个数组
private intPlaces: string[] = [];
I can't use .push
on it with the following: 我不能用以下内容使用.push
:
this.intPlaces.push(place.formatted_address);
ts is saying i can't use .push
on type {}
ts说我不能在类型{}
上使用.push
Not sure why it doesn't recognize this as an array 不知道为什么它不能将其识别为数组
Declare array like this, 像这样声明数组,
private intPlaces:any = [];
If place is array of object then, 如果地方是对象数组那么,
this.intPlaces.push(place[0].formatted_address);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.