Typescript 认为数组是一个对象
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>
我声明了一个数组
private intPlaces: string[] = [];
我无法将 .push
与以下内容一起使用:
this.intPlaces.push(place.formatted_address);
ts 说我不能在类型 {}
上使用 .push
不确定为什么它不能将其识别为数组
Declare array like this,
private intPlaces:any = [];
如果 place 是对象数组,那么,
this.intPlaces.push(place[0].formatted_address);
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>
我声明了一个数组
private intPlaces: string[] = [];
我无法将 .push
与以下内容一起使用:
this.intPlaces.push(place.formatted_address);
ts 说我不能在类型 {}
.push
不确定为什么它不能将其识别为数组
Declare array like this,
private intPlaces:any = [];
如果 place 是对象数组,那么,
this.intPlaces.push(place[0].formatted_address);