AngularJS adding ng-click in directive

ChruS picture ChruS · Nov 22, 2012 · Viewed 8.4k times · Source

I'm implementing drag'n'drop directive. On drop I add a copy of element to my div and append ng-click attribute to it like this:

copy.append('<button class="close" ng-click="abc()">&times;</button>');

For example, in controller I have

$scope.abc = function () {
    alert('Hello!');
}

And it doesn't work. If I add this button on page manually it works fine.

Answer

ChrisOdney picture ChrisOdney · Nov 22, 2012
copy.append('<button class="close" ng-click="abc()">&times;</button>');
$compile(copy)($scope);