0

I have an angular directive with a link scope.

In that scope, I append a div. I would like to add an event listener to this div.

When I do so, the event listener is overridden by the ng-click native attributes of the directive.

What is the best way forward? Trying to use element to identify the element does not work as element compiles asynchronously.

0

1 Answer 1

1

Why not just use ng-click?

link: function(scope, element, attrs) {
    scope.onHandleClick = function() {
        console.log('onHandleClick');
    };
}

<div ng-click="onHandleClick($event)"/>
Sign up to request clarification or add additional context in comments.

5 Comments

Because it's a child element within the div appended within the link scope.
It should still have visibility of this link scope.
$compile('<div class="childElement" ng-click="onHandleClick($event)">')(scope)
when I try your original post, the scope.onHandleClick function is not called; nothing happens.
Can we see your code where you create and append the div?

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.