angular-google-maps - ngfor 与 agm-circle 抛出错误 : Angular2

标签 angular-google-maps angular2-google-maps

我正在使用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/

相关文章:

angularjs - 如何将 GooglePlacesServices 与 angular-google-maps 一起使用

javascript - Famo-us Surface 内的 Google map 无法在移动设备上拖动

angularjs - Angular 谷歌地图 (AGM) 自动完成

用于谷歌地图的 Angular 2 agm 库按地点 id 设置地点

google-maps - Angular 2( Angular cli): Uncaught ReferenceError: google is not defined

javascript - 无法在 Angular 2 中的 Google map 上设置 ZoomControlOptions

javascript - 在 Angular 2 Google map 上移动 map 控件

javascript - Angular Google map - 如何向 map 添加方向

javascript - Angular-Google-Map : How to Load Map after Position Data Loaded(Lat, Lng)?

Angular 4 - 谷歌地图高度填充剩余空间