ngfor with agm-circle throws error : Angular2

3.9k views Asked by At

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

There are 1 answers

0
Kumail Hussain On BEST ANSWER

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