在angularjs中使用三元运算符在元素上设置属性 [英] Using ternary operator in angularjs to set an attribute on an element

查看:274
本文介绍了在angularjs中使用三元运算符在元素上设置属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 angularjs 1.6 ,并要求使用特定的 css 库,如果该按钮的定义如下,它将禁用该按钮:

I'm using angularjs 1.6 and required to use a specific css library that will disable a button if the button is defined like:

<button disabled="">
   My button
</button>

如果定义,将启用该按钮:

And will enable the button if defined:

<button disabled="">
   My button
</button>

我正在尝试根据服务中某个属性的最新值启用/禁用它我的控制器,但是即使未定义 someProperty ,按钮也始终显示为已启用..有任何想法吗?

I'm trying to enable/disable it based on the latest value from a property in a service within my controller, but the button is always showing as enabled even if someProperty is defined or not .. any ideas?

<button {{ ctrl.myService.getData().someProperty ? '' : 'disabled=""' }}>
   My button
</button>


推荐答案

尝试使用

<button ng-disabled="ctrl.myService.getData().someProperty ? 'disabled': '' ">
   My button
</button>

这篇关于在angularjs中使用三元运算符在元素上设置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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