Is it possible to have an OR in ng-switch-when?
<div ng-repeat="w in windows" ng-show="visibleWindowId == w.id" ng-switch="w.type"> <div ng-switch-when="val1 **OR** val2"> sup </div> </div>
If not, how could the above be accomplished?
Thanks :)
The ngSwitch directive is used to conditionally swap DOM structure on your template based on a scope expression.
ng-if is better in this regard. Using it in place of ng-show will prevent the heavy content from being rendered in the first place if the expression is false. However, its strength is also its weakness, because if the user hides the chart and then shows it again, the content is rendered from scratch each time.
The element with ngSwitchDefault is displayed only if no match is found. The inner element with ngSwitchDefault can be placed anywhere inside the container element and not necessarily at the bottom. If you add more than one ngSwitchDefault directive, all of them are displayed.
The ng-change event is triggered at every change in the value. It will not wait until all changes are made, or when the input field loses focus. The ng-change event is only triggered if there is a actual change in the input value, and not if the change was made from a JavaScript.
ngswitch
only allows you to compare a single condition.
I you are looking to test multiple conditions you can use ng-if
available with version 1.1.5
Reference
It is important to note that using ng-if
and ng-switch
remove the element from the DOM structure, opposed to show and hide.
This is important when you traverse the DOM to find elements.
This is now possible using ng-switch-when-separator
which was added to Angular documentation in 1.5.10:
<div ng-repeat="w in windows" ng-show="visibleWindowId == w.id" ng-switch="w.type"> <div ng-switch-when="val1|val2" ng-switch-when-separator="|"> sup </div> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With