将ng-if组合在一起

时间:2016-04-25 17:52:30

标签: html angularjs user-interface ng-show angular-ng-if

我希望我的两个ng-if能够一起工作而不是单独工作。如果两者都为真,那么只显示最后一个为真。我的代码现在看起来像这样。

<div>   
    <img ng-src="{{img(myColor)}}" ng-if="myColor">

    <img ng-src="{{img(myColor2)}}" ng-if="myColor2">
</div>

然而,当ng-if变为真时,这只会将它们叠加在一起。有没有办法一次只显示一个没有CSS

2 个答案:

答案 0 :(得分:3)

我可能很晚才建议解决方案。但我认为你可以用&amp;&amp ;;按位运算符。

以下是示例代码:

<div>   
    <img ng-src="{{img(myColor)}}" ng-if="myColor && !myColor2">

    <img ng-src="{{img(myColor2)}}" ng-if="myColor && myColor2">
</div>

答案 1 :(得分:0)

听起来你需要比简单标记所能提供的更复杂的逻辑。为什么不使用设置颜色的范围函数,然后使用合并标记。

$scope.setColor = function() {
  // Something that determines what color to set.
  $scope.color = ...;
};

并在你的javascript中

import java.io.IOException;

class CLS {
    public static void main(String... arg) throws IOException, InterruptedException {
        new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
    }
}
相关问题