2020 * On child elments add:
2121 *
2222 * * `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.
2528 *
2629 * @example
2730 <doc:example>
@@ -69,22 +72,28 @@ var ngSwitchDirective = valueFn({
6972 } ] ,
7073 link : function ( scope , element , attr , ctrl ) {
7174 var watchExpr = attr . ngSwitch || attr . on ,
72- selectedTransclude ,
73- selectedElement ,
74- selectedScope ;
75+ selectedTranscludes ,
76+ selectedElements ,
77+ selectedScopes ;
7578
7679 scope . $watch ( watchExpr , function ngSwitchWatchAction ( value ) {
77- if ( selectedElement ) {
80+ forEach ( selectedScopes , function ( selectedScope ) {
7881 selectedScope . $destroy ( ) ;
82+ } ) ;
83+ forEach ( selectedElements , function ( selectedElement ) {
7984 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 [ '?' ] ) ) {
8389 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+ } ) ;
8897 } ) ;
8998 }
9099 } ) ;
@@ -97,7 +106,8 @@ var ngSwitchWhenDirective = ngDirective({
97106 require : '^ngSwitch' ,
98107 compile : function ( element , attrs , transclude ) {
99108 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 ) ;
101111 } ;
102112 }
103113} ) ;
@@ -108,7 +118,8 @@ var ngSwitchDefaultDirective = ngDirective({
108118 require : '^ngSwitch' ,
109119 compile : function ( element , attrs , transclude ) {
110120 return function ( scope , element , attr , ctrl ) {
111- ctrl . cases [ '?' ] = transclude ;
121+ ctrl . cases [ '?' ] = ( ctrl . cases [ '?' ] || [ ] ) ;
122+ ctrl . cases [ '?' ] . push ( transclude ) ;
112123 } ;
113124 }
114125} ) ;
0 commit comments