“ng-switch on”和“ng-switch”的区别

时间:2022-08-22 17:00:17

I was studiously reading the AngularJS API reference for the ngSwitch directive when I came to that part :

当我读到这部分时,我正在认真地阅读关于ngSwitch指令的AngularJS API参考:

place an expression on the on="..." attribute (or the ng-switch="..." attribute)

将表达式放在on="…"属性(或ng-switch="…"属性)上

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

柱塞试验:http://plnkr.co/edit/vaq1t4744bnnc6rgzten?

1 个解决方案

#1


7  

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

没有区别。您可以查看ng-switch指令的源代码,https://github.com/angular/angular/angular.js/blob/master/src/ng/directive/ngswitch.js。

var watchExpr = attr.ngSwitch || attr.on

#1


7  

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

没有区别。您可以查看ng-switch指令的源代码,https://github.com/angular/angular/angular.js/blob/master/src/ng/directive/ngswitch.js。

var watchExpr = attr.ngSwitch || attr.on