From 0f806d9659b5b89a4bd9493364bc36398677e939 Mon Sep 17 00:00:00 2001 From: The Big Red Geek Date: Fri, 29 Aug 2014 22:03:13 -0700 Subject: [PATCH] refactor(ngSwitch): remove undocumented `change` attribute from ngSwitch BREAKING CHANGE: Ever since 0df93fd, tagged in v1.0.0rc1, the ngSwitch directive has had an undocumented `change` attribute, used for evaluating a scope expression when the switch value changes. While it's unlikely, applications which may be using this feature should work around the removal by adding a custom directive which will perform the eval instead. Directive controllers are re-instantiated when being transcluded, so by putting the attribute on each item that you want to be notified of a change to, you can more or less emulate the old behaviour. Example: ```js angular.module("switchChangeWorkaround", []). directive("onSwitchChanged", function() { return { linke: function($scope, $attrs) { $scope.$parent.$eval($attrs.change); } }; }); ``` ```html
``` Closes #8858 Closes #8822 --- src/ng/directive/ngSwitch.js | 1 - test/ng/directive/ngSwitchSpec.js | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index c30f8c18..1a4c87bb 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -165,7 +165,6 @@ var ngSwitchDirective = ['$animate', function($animate) { selectedScopes.length = 0; if ((selectedTranscludes = ngSwitchController.cases['!' + value] || ngSwitchController.cases['?'])) { - scope.$eval(attr.change); forEach(selectedTranscludes, function(selectedTransclude) { selectedTransclude.transclude(function(caseElement, selectedScope) { selectedScopes.push(selectedScope); diff --git a/test/ng/directive/ngSwitchSpec.js b/test/ng/directive/ngSwitchSpec.js index ceadac7a..30875668 100644 --- a/test/ng/directive/ngSwitchSpec.js +++ b/test/ng/directive/ngSwitchSpec.js @@ -208,19 +208,6 @@ describe('ngSwitch', function() { expect(element.text()).toEqual('236'); })); - - it('should call change on switch', inject(function($rootScope, $compile) { - element = $compile( - '' + - '
{{name}}
' + - '
')($rootScope); - $rootScope.url = 'a'; - $rootScope.$apply(); - expect($rootScope.name).toEqual('works'); - expect(element.text()).toEqual('works'); - })); - - it('should properly create and destroy child scopes', inject(function($rootScope, $compile) { element = $compile( '' +