0

I need some operation like this:
user selects a html template, then the html will be injected by element.html('<span>A</span><span>B</span>....') in a directive.
i want to bind click event for all spans.
if i write like this element.html('<span ng-click="action()">A</span>'), this doesn`t work.
my question is how to bind event for those spans?

1 Answer 1

2

Use $compile for Angular to recognize it:

element.html(
    $compile('<span ng-click="action()">A</span>')(scope)
);
Sign up to request clarification or add additional context in comments.

1 Comment

awesome! it works ^_^, but i use element.append instead of element.html

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.