"ng-switch on" and "ng-switch" difference
Asked Answered
W

1

14

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

Whitver answered 22/7, 2015 at 9:48 Comment(0)
O
13

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
Ocana answered 22/7, 2015 at 12:19 Comment(2)
Yes, that's what I was expecting. So I just doesn't understand why there are two syntax. Not really usefull and potentially confusing :)Whitver
One use for the on syntax is that you can use ng-switch as a tag: <ng-switch on="...">Tinishatinker

© 2022 - 2024 — McMap. All rights reserved.