Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"ng-switch on" and "ng-switch" difference

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

like image 443
Brain Up Avatar asked Jul 22 '15 09:07

Brain Up


People also ask

What is ng switch?

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.

What is Ng show and Ng hide?

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 .

What does ng model do?

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.

Which directive allows to conditionally swaps the contents of a section based upon matched value?

The ngSwitch directive is used to conditionally swap DOM structure on your template based on a scope expression.

What is ng switch in AngularJS?

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.

What is the difference between ngswitch and ngswitchcase?

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.

How do you match expressions in ngswitch?

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.

What happens if there are no matches in ngswitchdefault?

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.


1 Answers

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
like image 154
Yurii K Avatar answered Oct 11 '22 21:10

Yurii K