[英]Angular Directive failed to add element icon
I try using Angular directive to make a button dynamically. 我尝试使用Angular指令动态创建按钮。
Here is my current code: 这是我当前的代码:
function rippleButton() {
return {
restrict: 'E',
compile: function (element, attributes) {
element.addClass('btn waves-effect waves-light');
if (attributes.color) {
element.addClass('btn-' + attributes.color);
}
if (attributes.size) {
element.addClass('btn-' + attributes.size);
}
if (attributes.type == "Submit") {
element.addClass('btn-primary');
}
if (attributes.icon) {
element.append("<i class=fa " + attributes.icon + "></i>");
}
}
};
}
and my html: <ripple-button type="button" data-color="danger" icon="fa-search">Filter</ripple-button>
和我的html: <ripple-button type="button" data-color="danger" icon="fa-search">Filter</ripple-button>
everything works perfectly except for the icon. 除图标外,其他所有功能均正常运行。 When it render to browser it became: 当呈现给浏览器时,它变成:
<ripple-button type="button" data-color="danger" icon="fa-search" class="btn waves-effect waves-light btn-danger">Filter<i class="fa" fa-search=""></i></ripple-button>
The fa-search
not combining with <i class="">
. fa-search
未与<i class="">
结合使用。
What should i do to make it work? 我应该怎么做才能使其正常工作?
Thanks 谢谢
I havent tested this, but try to change 我还没有测试过,但是尝试改变
element.append("<i class=fa " + attributes.icon + "></i>");
to 至
element.append("<i class='fa " + attributes.icon + "'></i>");
I think that might do the trick. 我认为可能可以解决问题。
我已经测试了以下代码,并且可以正常工作:
element.append("<i class='fa " + attributes.icon + "'></i>");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.