AngularJS - 有条件地应用属性? [英] AngularJS - Conditionally apply an attribute?

查看:43
本文介绍了AngularJS - 有条件地应用属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有条件地应用一个元素很容易 - 只需使用 ng-show.但是属性呢?

浏览器

...

只需要管理员可以排序,所以做一些类似的事情......

...

解决方案

创建自定义指令或模板,并在带有 sortable 附加的版本和没有附加的版本之间切换.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆