user1387717
user1387717

Reputation: 1049

angularjs select element if false OR null/undefined

I have the code below but I would like "No" to be selected if s.x.user_chose_is_formula is false, null, or undefined (all in a single option). How do I do that?

            md-input-container.values-type-select
              label Values Type:
              md-select(ng-model="s.x.user_chose_is_formula")
                md-option(ng-value="true") Yes
                md-option(ng-value="false") No

Upvotes: 0

Views: 319

Answers (1)

danday74
danday74

Reputation: 57225

If (myvar == null) {
}

Checks for null or undefined, intentional use of double equals:

If (myvar === false) {
}

Checks for false, intentional use of triple equals:

If (myvar != null && myvar !== false) {
}

Update

You can ignore the older answer above, but it may be helpful to you. In your controller you should initialise your variable so it is either true or false and never null or undefined. If you don't have a controller use ng-in it.

Upvotes: 0

Related Questions