在 angularjs 中使用三元运算符设置元素的属性

Using ternary operator in angularjs to set an attribute on an element

我正在使用 angularjs 1.6 并且需要使用特定的 css 库,如果按钮定义如下:

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

如果定义了按钮将启用:

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

我正在尝试 enable/disable 它基于我控制器内服务中 属性 的最新值,但按钮始终显示为已启用,即使 someProperty是否已定义..有什么想法吗?

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

我们可以使用 ng-disabled 属性来实现。所以就像:

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

如果有帮助请告诉我。

尝试使用

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