[英]How to pass fontAwesome icon to CSS content via data attribute
I'm using a mixture of angular, html and css for my frontend build and I'm trying to change a font awesome icon onclick with angular. 我正在使用angular,html和css的混合物作为我的前端构建,我正在尝试使用angular更改字体真棒图标。 However, I can't get it to pass the unicode to css and display the correct icon. 但是,我无法让它将unicode传递给css并显示正确的图标。 It just prints out the unicode instead. 它只打印出unicode。
Here is my CSS: 这是我的CSS:
&:before {
content: attr(data-icon);
font-family: "fontAwesome";
font-size: 2em;
position: absolute;
left: .65em;
top: .25em;
}
My html/angular: 我的html / angular:
<div class="accordion--title" ng-click="showAccordionDetail = !showAccordionDetail" ng-attr-data-icon="{{showAccordionDetail && '\f107' || '\f106' }}">
Use ng-class
, much easier to do this: 使用ng-class
,更容易做到这一点:
<div
ng-init="showAccordionDetail = false"
class="accordion--title"
ng-click="showAccordionDetail = !showAccordionDetail"
ng-class="{true:'fa fa-angle-down', false: 'fa fa-angle-right'}[showAccordionDetail]">
click me
</div>
As Enkode's answer, it's easier to use ng-class
but I've made some changes to make it simpler. 作为Enkode的答案,使用ng-class
更容易,但我做了一些修改以使其更简单。
<div ng-init="showAccordionDetail = false"
class="accordion--title"
ng-click="showAccordionDetail = !showAccordionDetail"
ng-class="{'fa fa-angle-down': showAccordionDetail, 'fa fa-angle-right': !showAccordionDetail}">
click me
</div>
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.