I am using "@angular/cli": "1.0.2" and angular version 4.
For some reason I had to use jquery based plugin for select area because I couldn't found equivalent plugin in angular.
This is how my component looks like
declare var $ : any;
//adding only necessary code
export class SelectComponent implements OnInit {
constructor(private _ngZone: NgZone) {}
public rowData: any = [];
ngOnInit() {
$('img#example').selectAreas({
minSize: [10, 10],
onChanged: this.debugQtyAreas,
width: 500,
areas: [{
x: 10,
y: 20,
width: 60,
height: 100,
}]
});
}
debugQtyAreas(event, id, areas) {
this.rowData = areas.map(function(obj) {
return {
left: obj.x,
top: obj.y,
id: obj.id
};
});
};
}
Some how this way my jquery thing is working I am able to select areas on a Image.
But the value I am pushing / assigning to array rowData are not updating in the view
I tried searching on internet and found this solution working for everyone but not for me
this._ngZone.run(() => {
//running code inside this
})
But I am getting error here as
Cannot read property 'run' of undefined
Same thing happening with rowData, when I tried to push data instead of assigning it from map like following
for(var i = 0; i < areas.length; i++){
this.rowData.push({
left: areas[i].x,
top: areas[i].y,
id: obj.id
});
}
It says Cannot read property 'push' of undefined
NgZone?import { NgZone } from '@angular/core';this ? Yes did.