I was studiously reading the AngularJS API reference for the ngSwitch directive when I came to that part :
place an expression on the on="..." attribute (or the ng-switch="..." attribute)
So of course I was wondering why there are two ways to place the expression since both of them seems to work the same way.
<div ng-switch="expression">
<div ng-switch on="expression">
I assume there is a reason but I do not find anything for now.
Plunker to test : http://plnkr.co/edit/VAq1t4744bnNC6RgZtEn?p=preview
Definition and Usage. The ng-switch directive lets you hide/show HTML elements depending on an expression. Child elements with the ng-switch-when directive will be displayed if it gets a match, otherwise the element, and its children will be removed.
The ng-show directive shows or hides the given HTML element based on the expression provided to the ng-show attribute. The ng-hide directive shows or hides the given HTML element based on the expression provided to the ng-hide attribute .
ngModel is a directive which binds input, select and textarea, and stores the required user value in a variable and we can use that variable whenever we require that value. It also is used during validations in a form.
The ngSwitch directive is used to conditionally swap DOM structure on your template based on a scope expression.
AngularJS ng-switch Directive 1 Definition and Usage. The ng-switch directive lets you hide/show HTML elements depending on an expression. ... 2 Syntax. Supported by all HTML elements. 3 Parameter Values. An expression that will remove elements with no match, and display elements with a match.
The NgSwitch directive specifies an expression to match against. The NgSwitchCase directive defines the expressions to match. It renders every view that matches. If there are no matches, the view with the NgSwitchDefault directive is rendered.
The expressions to match are provided by ngSwitchCase directives on views within the container. Every view that matches is rendered. If there are no matches, a view with the ngSwitchDefault directive is rendered. Elements within the [ NgSwitch] statement but outside of any NgSwitchCase or ngSwitchDefault directive are preserved at the location.
If there are no matches, the view with the NgSwitchDefault directive is rendered. Elements outside of any NgSwitchCase or NgSwitchDefault directive but within the NgSwitch statement but are preserved at the location.
There is no difference. You can check the sources of ng-switch directive https://github.com/angular/angular.js/blob/master/src/ng/directive/ngSwitch.js
var watchExpr = attr.ngSwitch || attr.on
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