I have code similar to the below code to trigger a click
event in an Angular app. Why is not the event triggering?
var app = angular.module("myApp", [])
app.directive('myTop',function($compile) {
return {
restrict: 'E',
template: '<div></div>',
replace: true,
link: function (scope, element) {
var childElement = '<button ng-click="clickFunc()">CLICK</button>';
element.append(childElement);
$compile(childElement)(scope);
scope.clickFunc = function () {
alert('Hello, world!');
};
}
}
})
$compile
, you'll see it accepts a string. docs.angularjs.org/api/ng/service/$compile#usage – Jess