AngularJS - 有条件地应用属性? [英] AngularJS - Conditionally apply an attribute?
本文介绍了AngularJS - 有条件地应用属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有条件申请的元素很容易 - 只需使用NG-表演。但对于一个属性?
IE
<格UI可排序>
...
< / DIV>
需要只为管理员进行排序,所以做这样的事情...
< DIV NG-条件属性={UI可排序':'user.isAdmin()}>
...
< / DIV>
解决方案
创建版本排序连接和版本之间没有自定义指令或模板和切换。
Conditionally applying an element is easy - just use ng-show. But what about an attribute?
IE
<div ui-sortable>
...
</div>
needs to be sortable only for admins, so do something like...
<div ng-conditional-attribute=" {'ui-sortable': 'user.isAdmin()'} ">
...
</div>
解决方案
Create a custom directive or template and switch between the version with sortable attached and the version without.
这篇关于AngularJS - 有条件地应用属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文