angularjs if else声明

时间:2015-07-01 09:27:14

标签: javascript angularjs

<ng-switch on="MyData.Status">
    <p ng-switch-when="2">
        <p ng-if="MyData.SomeProp == false">
            Message 1
        </p>
        <p ng-if="MyData.SomeProp == true">
            Message 2
        </p>
    </p>
</ng-switch>

我想仅在ng-switch-when =“2时执行MyData.SomeProp == false代码块。

伪代码将是

if (MyData.Status == 2){
   if (MyData.SomeProp == false){
      print message 1
   } 
   else{
      print message 2
   }
}

如何使用angularjs

执行此简单语句

1 个答案:

答案 0 :(得分:4)

使用ng-show代替ng-if

<ng-switch on="MyData.Status">
    <p ng-switch-when="2">
        <p ng-show="MyData.SomeProp == false">
            Message 1
        </p>
        <p ng-show="MyData.SomeProp == true">
            Message 2
        </p>
    </p>
</ng-switch>