After the datatable once get rendered , I am not able to update data. I am using angular2-datatable.
In my appcomponent.html:
If I update data2 in my appcomponent.ts file like this:
this.httpservice.getdata().subscribe
(data=>
{ this.data2=data;
for (i = 0; i < 21; i++) {
markerarray[i] = new google.maps.Marker({
position: new google.maps.LatLng(this.data2[i].latituide, this.data2
[i].longituide), //In this line
title: this.data2[i].name, //and this
map: map
});
}
google.maps.event.addListener(map, 'idle', function () {
var bounds = map.getBounds();
for (var i = 0; i < 20; i++) {
var marker = markerarray[i];
if (bounds.contains(marker.getPosition()) === true) {
this.data2.length=0;// This is not working for me
}
}
});
})
I want to empty the datatable once the markers are in bound.
I figured out a solution , though I am not sure that this is the best way.
I have used ChangeDetectorRef for detecting changes.
constructor(private http: Http,private httpservice: HttpService,private ref: ChangeDetectorRef) {
ref.detach();
setInterval(() => {
this.ref.detectChanges();
},1000);
}