ngfor with agm-circle throws error : Angular2

风格不统一 提交于 2019-12-11 17:33:51

问题


I am using agm (angular google maps) and want to draw n number of circles using ngfor but i am getting an error :

Can't bind to 'ngFor' since it isn't a known property of 'agm-circle'.

this is my 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>

this is my ts file having data:

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'},
    ];

  }

as for as these are dummies data but this data of circles will be n any suggestion will be appreciated


回答1:


i have resolved the issue by tweaking ngFor with the key-word let I dont know why AGM is not supporting the above syntax however my new:

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>

Hope it will be helpful :-p



来源:https://stackoverflow.com/questions/46345140/ngfor-with-agm-circle-throws-error-angular2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!