10

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.

0

2 Answers 2

8
copy.append('<button class="close" ng-click="abc()">&times;</button>');
$compile(copy)($scope);
Sign up to request clarification or add additional context in comments.

Comments

0

I guess that you do need to compile your new template so that AngularJS recognizes it. The docs give you a good example for how to use ng.$compile.

Cloning can be done then like so:

var templateHTML = angular.element('<p>{{total}}</p>'),
    scope = ....;

var clonedElement = $compile(templateHTML)(scope, function(clonedElement, scope) {
  //attach the clone to DOM document at the right place
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.