角NG-风格,有条件的前pression

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