diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index 9abe61ca..05bfdd7a 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -166,9 +166,8 @@ var ngSwitchDirective = ['$animate', function($animate) { if ((selectedTranscludes = ngSwitchController.cases['!' + value] || ngSwitchController.cases['?'])) { scope.$eval(attr.change); forEach(selectedTranscludes, function(selectedTransclude) { - var selectedScope = scope.$new(); - selectedScopes.push(selectedScope); - selectedTransclude.transclude(selectedScope, function(caseElement) { + selectedTransclude.transclude(function(caseElement, selectedScope) { + selectedScopes.push(selectedScope); var anchor = selectedTransclude.element; selectedElements.push(caseElement); @@ -183,7 +182,7 @@ var ngSwitchDirective = ['$animate', function($animate) { var ngSwitchWhenDirective = ngDirective({ transclude: 'element', - priority: 800, + priority: 1200, require: '^ngSwitch', multiElement: true, link: function(scope, element, attrs, ctrl, $transclude) { @@ -194,7 +193,7 @@ var ngSwitchWhenDirective = ngDirective({ var ngSwitchDefaultDirective = ngDirective({ transclude: 'element', - priority: 800, + priority: 1200, require: '^ngSwitch', multiElement: true, link: function(scope, element, attr, ctrl, $transclude) { diff --git a/test/ng/directive/ngSwitchSpec.js b/test/ng/directive/ngSwitchSpec.js index 48e27ae9..1e7bf8fa 100644 --- a/test/ng/directive/ngSwitchSpec.js +++ b/test/ng/directive/ngSwitchSpec.js @@ -241,7 +241,7 @@ describe('ngSwitch', function() { $rootScope.url = 'x'; $rootScope.$apply(); expect(getChildScope()).toBeUndefined(); - expect(child1.$destroy).toHaveBeenCalledOnce(); + expect(child1.$destroy).toHaveBeenCalled(); $rootScope.url = 'a'; $rootScope.$apply(); @@ -251,6 +251,28 @@ describe('ngSwitch', function() { })); + it("should use the correct transclusion scope if there is a transclude directive on the ng-swith-when/ng-switch-default element", inject(function($rootScope, $compile) { + element = $compile( + '
' +
+ 'foo = {{foo}}' +
+ 'bar = {{bar}}' +
+ '$index = {{$index}}' +
+ '' +
+ '