具有条件表达式的AngularJS ng样式 [英] AngularJS ng-style with a conditional expression

查看:82
本文介绍了具有条件表达式的AngularJS ng样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理这样的问题:

I am handling my issue like this:

ng-style="{ width: getTheValue() }"

但是为了避免在控制器端具有此功能,我更喜欢这样做:

But to avoid having this function on the controller side, I would much prefer to do something like this:

ng-style="{ width: myObject.value == 'ok' ? '100%' : '0%' }"

我该怎么做?

推荐答案

正如@Yoshi所说,从1.1.5版本开始,您可以直接使用它.

As @Yoshi said, from angular 1.1.5 you can use-it without any change.

如果使用角度< 1.1.5,您可以使用 ng-class .

If you use angular < 1.1.5, you can use ng-class.

.largeWidth {
    width: 100%;
}

.smallWidth {
    width: 0%;
}

// [...]

ng-class="{largeWidth: myVar == 'ok', smallWidth: myVar != 'ok'}"

这篇关于具有条件表达式的AngularJS ng样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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