我正在使用agm(角度谷歌地图)并想使用ngfor绘制n个圆圈,但我收到错误:
Can't bind to 'ngFor' since it isn't a known property of 'agm-circle'.
这是我的 html:
<agm-circle *ngFor="data in circles"
[latitude]="data.lat"
[longitude]="data.lng"
[circleDraggable]="true"
[editable]="true"
[fillColor]="'data.color'"
[radius]="data.radius"
>
</agm-circle>
这是我的 ts 文件,其中包含数据:
lat: number;
lng: number;
circle: any;
@ViewChild(AgmPolygon) polygon: any;
path = [
{ lat: 51.791629704426924, lng: 7.809007 },
{ lat: 51.974729774949644, lng: 0.6317138671875 },
{ lat: 51.303145259199056, lng: 0.6646728515625 },
{ lat: 51.416338106400396, lng: -0.4779052734375 }
];
constructor () {
this.lat = 51.678418;
this.lng = 7.809007;
this.circle = [
{lat: 51.79, lng: 7.8, radius: 60000, color: 'red'},
{lat: 52.79, lng: 12.8, radius: 60000, color: 'green'},
{lat: 54.79, lng: 10.8, radius: 60000, color: 'yellow'},
{lat: 51.79, lng: 8.8, radius: 60000, color: 'yellow'},
{lat: 60.79, lng: 7.8, radius: 60000, color: 'green'},
];
}
至于这些是虚拟数据,但这些圆圈数据将n任何建议将不胜感激
最佳答案
我已经通过使用关键字 let 调整 ngFor 解决了这个问题,我不知道为什么 AGM 不支持上述语法,但是我的新语法:
Index.html
<agm-circle *ngFor="let data of circle"
[latitude]="data.lat"
[longitude]="data.lng"
[circleDraggable]="true"
[editable]="true"
[fillColor]="data.color"
[radius]="data.radius"
>
</agm-circle>
希望对您有所帮助:-p
关于angular-google-maps - ngfor 与 agm-circle 抛出错误 : Angular2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46345140/