1
<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>

I want to execute MyData.SomeProp == false block of code only when ng-switch-when="2.

pseudo code would be

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

how to do this simple statement using angularjs

1
  • are you using php also? Commented Jul 1, 2015 at 9:28

1 Answer 1

4

Use ng-show instead of 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>
Sign up to request clarification or add additional context in comments.

2 Comments

Although you could do it without the ==true and ==false bits.
@Stu I think == true is required, if the value of SomeProp is truefalse, anything other than true or false. We don't know it yet, better to go safer side

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.