Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 0f806d9

Browse files
thebigredgeekcaitp
authored andcommitted
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 <div ng-switch="switcher"> <div ng-switch-when="a" on-switch-changed="doSomethingInParentScope()"></div> <div ng-switch-when="b" on-switch-changed="doSomethingInParentScope()"></div> </div> ``` Closes #8858 Closes #8822
1 parent ac53554 commit 0f806d9

File tree

2 files changed

+0
-14
lines changed

2 files changed

+0
-14
lines changed

src/ng/directive/ngSwitch.js

-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ var ngSwitchDirective = ['$animate', function($animate) {
165165
selectedScopes.length = 0;
166166

167167
if ((selectedTranscludes = ngSwitchController.cases['!' + value] || ngSwitchController.cases['?'])) {
168-
scope.$eval(attr.change);
169168
forEach(selectedTranscludes, function(selectedTransclude) {
170169
selectedTransclude.transclude(function(caseElement, selectedScope) {
171170
selectedScopes.push(selectedScope);

test/ng/directive/ngSwitchSpec.js

-13
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,6 @@ describe('ngSwitch', function() {
208208
expect(element.text()).toEqual('236');
209209
}));
210210

211-
212-
it('should call change on switch', inject(function($rootScope, $compile) {
213-
element = $compile(
214-
'<ng:switch on="url" change="name=\'works\'">' +
215-
'<div ng-switch-when="a">{{name}}</div>' +
216-
'</ng:switch>')($rootScope);
217-
$rootScope.url = 'a';
218-
$rootScope.$apply();
219-
expect($rootScope.name).toEqual('works');
220-
expect(element.text()).toEqual('works');
221-
}));
222-
223-
224211
it('should properly create and destroy child scopes', inject(function($rootScope, $compile) {
225212
element = $compile(
226213
'<ng:switch on="url">' +

0 commit comments

Comments
 (0)