diff options
| author | Lucas Galfasó | 2013-03-03 22:23:29 -0300 |
|---|---|---|
| committer | James deBoer | 2013-03-11 11:31:04 -0700 |
| commit | e88d6179c3a6a137e75fa09de906fc83c6515db2 (patch) | |
| tree | bee7a8a3cb8a4cbcd6304baf456233a66f4f15d6 /src/ng/directive/ngSwitch.js | |
| parent | 90ba9aadc6693e01487e6e14e7d1065658572e0f (diff) | |
| download | angular.js-e88d6179c3a6a137e75fa09de906fc83c6515db2.tar.bz2 | |
feat(ng:switch): Preserve the order of the elements not in the ng-switch
Preserve the order of the elements that are not part of a case nor default in
a ng-switch directive
BREAKING CHANGE: elements not in the ng-switch were rendered after the
ng-switch elements. Now they are rendered in-place.
Ng-switch directives should be updated with non ng-switch elements
in render-order. e.g.
The following was previously rendered with <li>1</li> after "2":
<ul ng-switch="select">
<li>1</li>
<li ng-switch-when="option">2</li>
</ul>
To keep the old behaviour, say:
<ul ng-switch="select">
<li ng-switch-when="1">2</li>
<li>1</li>
</ul>
Closes #1074
Diffstat (limited to 'src/ng/directive/ngSwitch.js')
| -rw-r--r-- | src/ng/directive/ngSwitch.js | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index aa04a998..88b1e701 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -6,13 +6,16 @@ * @restrict EA * * @description - * Conditionally change the DOM structure. + * Conditionally change the DOM structure. Elements within ngSwitch but without + * ngSwitchWhen or ngSwitchDefault directives will be preserved at the location + * as specified in the template * * @usageContent * <ANY ng-switch-when="matchValue1">...</ANY> * <ANY ng-switch-when="matchValue2">...</ANY> * ... * <ANY ng-switch-default>...</ANY> + * <ANY>...</ANY> * * @scope * @param {*} ngSwitch|on expression to match against <tt>ng-switch-when</tt>. @@ -26,6 +29,7 @@ * are multiple default cases, all of them will be displayed when no other * case match. * + * * @example <doc:example> <doc:source> @@ -90,9 +94,9 @@ var ngSwitchDirective = valueFn({ forEach(selectedTranscludes, function(selectedTransclude) { var selectedScope = scope.$new(); selectedScopes.push(selectedScope); - selectedTransclude(selectedScope, function(caseElement) { + selectedTransclude.transclude(selectedScope, function(caseElement) { selectedElements.push(caseElement); - element.append(caseElement); + selectedTransclude.element.after(caseElement); }); }); } @@ -107,7 +111,7 @@ var ngSwitchWhenDirective = ngDirective({ compile: function(element, attrs, transclude) { return function(scope, element, attr, ctrl) { ctrl.cases['!' + attrs.ngSwitchWhen] = (ctrl.cases['!' + attrs.ngSwitchWhen] || []); - ctrl.cases['!' + attrs.ngSwitchWhen].push(transclude); + ctrl.cases['!' + attrs.ngSwitchWhen].push({ transclude: transclude, element: element }); }; } }); @@ -119,7 +123,7 @@ var ngSwitchDefaultDirective = ngDirective({ compile: function(element, attrs, transclude) { return function(scope, element, attr, ctrl) { ctrl.cases['?'] = (ctrl.cases['?'] || []); - ctrl.cases['?'].push(transclude); + ctrl.cases['?'].push({ transclude: transclude, element: element }); }; } }); |
