我有类似于以下代码的代码来触发click
Angular应用程序中的事件.为什么事件不会触发?
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!');
};
}
}
})
Run Code Online (Sandbox Code Playgroud)