2
在角度上,我需要根据不同的条件应用不同的样式属性,但它不是以这种方式工作,我只能应用条件表达式的两个条件。如何根据ng样式指令中的多个条件应用多个样式?
<div ng-style="
(status=="up") ?{'background-color':'green' ,'color':'green'}
(status=="down")?{'background-color':'red' ,'color':'red'}
(status=="idle")?{'background-color':'yellow','color':'yellow'}
(status=="") ?{'background-color':'grey' ,'color':'grey'}
">
这将是更好,如果你知道任何的方式来传递属性返回风格OBJ为NG-风格像波纹管这古怪不能正常工作的功能!
$scope.styleFn(status,attr) {
(status=="up") ?{attr:'green'}
(status=="down")?{attr:'red'}
(status=="idle")?{attr:'yellow'}
(status=="") ?{attr:'grey'}
}
<div ng-style="styleFn('up','background-color')">
这就是正确的,但你怎么通过属性的功能和生成定制的风格?这不是奇怪的工作,因为它应该。 – DragonKnight
只是将该属性传递给函数(上,下,空闲或空字符串),并且该函数将向其元素应用正确的样式。 – Karim
请再次检查我的问题。状态很好,attr不起作用。那是奇怪的部分。如果你通过''color''它确实返回'{'color':'#ff0000'}'例如但不在DOM中显示。 – DragonKnight