Am trying to add ng-click dynamically I know how it can be done in Jquery but don't know how I would do this in AngularJs. My code plots series of dots on a canvas and I want each dot to be clickable, am not sure how this can be done in Angular.
AngularJS Code:
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
$scope.data = [
[21,50],
[30,150],
[45,75],
[98,121],
[67,78],
[35,80]
];
$scope.addData = function() {
for(i=0; i<$scope.data.length; i++){
context.beginPath();
context.arc($scope.data[i][0], $scope.data[i][1], 10, 0, 2*Math.PI);
context.fillStyle = "#ccddff";
context.fill();
context.lineWidth = 1;
context.strokeStyle = "#666666";
context.stroke();
}
}
HTML code:
<canvas id="canvas" style="border: 1px gray solid; float: left;> width:500px; height:500px;"></canvas>
ng-clickevent on the canvas DOM element and because the canvas is static element, it should not be difficult to do this. See this for further details: stackoverflow.com/questions/19133825/…