问题描述:

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?

网友答案:

Use $compile for Angular to recognize it:

element.html(
    $compile('<span ng-click="action()">A</span>')(scope)
);
相关阅读:
Top