Angular ng-style for ::after

a 夏天 提交于 2019-12-02 07:26:14

All ng-style does is add inline styles. However you want to add a psuedo element ::after. According to the MDN:

You can use only one pseudo-element in a selector. It must appear after the simple selectors in the statement.

So inferred from that you can't use them inline, which sadly means ng-style can't do what your after.

However if your ::after is defined in a stylesheet you can use ng-class to dynamically add that style.

So

<hr ng-class="{'my-hr': <some condition to evaluate>}" />

Most cases that will suffice. However it looks like to want to dynamically set the content of ::after. So for that i can only imagine two options.

If you just want to simply add the string value use databinding

<hr />
{{name}}

However if you want extra styling on that string create a small directive as a re-usable widget may be the better option.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!