当前位置: 动力学知识库 > 问答 > 编程问答 >

angularjs - Angular element.html() event bind

问题描述:

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)
);
分享给朋友:
您可能感兴趣的文章:
随机阅读: