20
20
* On child elments add:
21
21
*
22
22
* * `ngSwitchWhen`: the case statement to match against. If match then this
23
- * case will be displayed.
24
- * * `ngSwitchDefault`: the default case when no other casses match.
23
+ * case will be displayed. If the same match appears multiple times, all the
24
+ * elements will be displayed.
25
+ * * `ngSwitchDefault`: the default case when no other case match. If there
26
+ * are multiple default cases, all of them will be displayed when no other
27
+ * case match.
25
28
*
26
29
* @example
27
30
<doc:example>
@@ -69,22 +72,28 @@ var ngSwitchDirective = valueFn({
69
72
} ] ,
70
73
link : function ( scope , element , attr , ctrl ) {
71
74
var watchExpr = attr . ngSwitch || attr . on ,
72
- selectedTransclude ,
73
- selectedElement ,
74
- selectedScope ;
75
+ selectedTranscludes ,
76
+ selectedElements ,
77
+ selectedScopes ;
75
78
76
79
scope . $watch ( watchExpr , function ngSwitchWatchAction ( value ) {
77
- if ( selectedElement ) {
80
+ forEach ( selectedScopes , function ( selectedScope ) {
78
81
selectedScope . $destroy ( ) ;
82
+ } ) ;
83
+ forEach ( selectedElements , function ( selectedElement ) {
79
84
selectedElement . remove ( ) ;
80
- selectedElement = selectedScope = null ;
81
- }
82
- if ( ( selectedTransclude = ctrl . cases [ '!' + value ] || ctrl . cases [ '?' ] ) ) {
85
+ } ) ;
86
+ selectedElements = [ ] ;
87
+ selectedScopes = [ ] ;
88
+ if ( ( selectedTranscludes = ctrl . cases [ '!' + value ] || ctrl . cases [ '?' ] ) ) {
83
89
scope . $eval ( attr . change ) ;
84
- selectedScope = scope . $new ( ) ;
85
- selectedTransclude ( selectedScope , function ( caseElement ) {
86
- selectedElement = caseElement ;
87
- element . append ( caseElement ) ;
90
+ forEach ( selectedTranscludes , function ( selectedTransclude ) {
91
+ var selectedScope = scope . $new ( ) ;
92
+ selectedScopes . push ( selectedScope ) ;
93
+ selectedTransclude ( selectedScope , function ( caseElement ) {
94
+ selectedElements . push ( caseElement ) ;
95
+ element . append ( caseElement ) ;
96
+ } ) ;
88
97
} ) ;
89
98
}
90
99
} ) ;
@@ -97,7 +106,8 @@ var ngSwitchWhenDirective = ngDirective({
97
106
require : '^ngSwitch' ,
98
107
compile : function ( element , attrs , transclude ) {
99
108
return function ( scope , element , attr , ctrl ) {
100
- ctrl . cases [ '!' + attrs . ngSwitchWhen ] = transclude ;
109
+ ctrl . cases [ '!' + attrs . ngSwitchWhen ] = ( ctrl . cases [ '!' + attrs . ngSwitchWhen ] || [ ] ) ;
110
+ ctrl . cases [ '!' + attrs . ngSwitchWhen ] . push ( transclude ) ;
101
111
} ;
102
112
}
103
113
} ) ;
@@ -108,7 +118,8 @@ var ngSwitchDefaultDirective = ngDirective({
108
118
require : '^ngSwitch' ,
109
119
compile : function ( element , attrs , transclude ) {
110
120
return function ( scope , element , attr , ctrl ) {
111
- ctrl . cases [ '?' ] = transclude ;
121
+ ctrl . cases [ '?' ] = ( ctrl . cases [ '?' ] || [ ] ) ;
122
+ ctrl . cases [ '?' ] . push ( transclude ) ;
112
123
} ;
113
124
}
114
125
} ) ;
0 commit comments