角NG-风格,有条件的前pression [英] Angular ng-style with a conditional expression

查看:123
本文介绍了角NG-风格,有条件的前pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在处理我的问题是这样的:

Right now, I am handling my issue like this:

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

但为了避免在控制器端这个功能,我更preFER做这样的事情:

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%' }"

我怎样才能做到这一点?谢谢!

How can I do this? Thank you!

推荐答案

由于@Yoshi说,从角1.1.5可以使用,它没有任何改变。

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

如果您使用的角度< 1.1.5,您可以使用纳克级

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'}"

这篇关于角NG-风格,有条件的前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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