angular-google-maps: agm-polygon not working properly with *ngFor, InvalidValueError: not an Array
Issue description Hi guys, I have a little problem with moving paths into a separated model. Let’s say I have a collection of restaurant. Each restaurant has a collection of delivery zones, each delivery zone has separated paths.
After changing [paths]="paths"
into [paths]="zone.paths"
I get
InvalidValueError: not an Array
My code is pretty simple:
<agm-map [latitude]="restaurant.latitude" [longitude]="restaurant.longitude">
<agm-marker [latitude]="restaurant.latitude" [longitude]="restaurant.longitude"></agm-marker>
<agm-polygon *ngFor="let zone of restaurant.delivery_zones" [fillColor]="red"
[fillOpacity]="0.5" [paths]="zone.paths"
[strokeColor]="blue" [strokeOpacity]="0.6" [strokeWeight]="2"
[visible]="true" [zIndex]="1"></agm-polygon>
</agm-map>
DeliveryZone model:
...
public paths = [
{lat: 25.774, lng: -80.190},
{lat: 18.466, lng: -66.118},
{lat: 32.321, lng: -64.757}
];
...
I’m not an expert in Angular.
Thanks!
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 16
@tolvaly heres what the html snippet looks like for my map:
where ‘paths’ or ‘this.paths’ is produced by this function:
In which, I utilize ‘this._loader.load()’ where ‘this._loader’ is ‘MapsAPILoader’, defined in my constructor.
Later, for more detailed lines, I did the following to gain full access to the google maps api:
make sure to have ‘declare var google: any;’ at the top, along side your imports or you won’t be able to use the google objects like google.maps.Marker, etc.
Hope this helps!
I faced the same issue but was fixed after I mapped my data format from
Array<LatLngLiteral>
toArray<Array<LatLngLiteral>>
Working format
Seems like the
Array<LatLng | LatLngLiteral>
format is not working.package.json