I am using an angular custom directive called 'teeth' to create multiple canvas elements on the HTML page. I placed another custom directive 'draw' , inside teeth directive, I want to call 'draw' directive when canvas element clicked. I have tried this, but element click event is not working. Please suggest me a solution.
(function () {
var controller = function ($scope) {
};
controller.$inject = ['$scope'];
var teeth = function () {
return {
restrict: 'E',
controller: controller,
link: function ($scope, element, attrs) {
function init(){
var count = 5;
var html = '<div class="row">'
for(var i=0; i<count;i++){
html += '<div class="test">'+
'<canvas id="'+i+'" width="58px" height="58px" draw></canvas>'+
'</div>';
}
html += '</div>';
element.html(html);
}
init();
}
}
};
angular.module('graphApp').directive('teeth', teeth);
}());
(function () {
var controller = function ($scope) {
};
controller.$inject = ['$scope'];
var draw = function () {
return {
restrict: 'A',
scope: {
id: '@id'
},
controller: controller,
link: function ($scope, element, attrs) {
element.on('click',function(event){
alert('element '+$scope.id+' clicked');
});
}
}
};
angular.module('graphApp').directive('draw', draw);
}());