This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -3401,7 +3401,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3401
3401
if ( ! optional && ! hasOwnProperty . call ( attrs , attrName ) ) {
3402
3402
destination [ scopeName ] = attrs [ attrName ] = undefined ;
3403
3403
}
3404
- attrs . $observe ( attrName , function ( value ) {
3404
+ removeWatch = attrs . $observe ( attrName , function ( value ) {
3405
3405
if ( isString ( value ) || isBoolean ( value ) ) {
3406
3406
var oldValue = destination [ scopeName ] ;
3407
3407
recordChanges ( scopeName , value , oldValue ) ;
@@ -3420,6 +3420,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
3420
3420
destination [ scopeName ] = lastValue ;
3421
3421
}
3422
3422
initialChanges [ scopeName ] = new SimpleChange ( _UNINITIALIZED_VALUE , destination [ scopeName ] ) ;
3423
+ removeWatchCollection . push ( removeWatch ) ;
3423
3424
break ;
3424
3425
3425
3426
case '=' :
Original file line number Diff line number Diff line change @@ -4336,6 +4336,37 @@ describe('$compile', function() {
4336
4336
} ) ;
4337
4337
} ) ;
4338
4338
4339
+ it ( 'should clean up `@`-binding observers when re-assigning bindings' , function ( ) {
4340
+ var constructorSpy = jasmine . createSpy ( 'constructor' ) ;
4341
+ var prototypeSpy = jasmine . createSpy ( 'prototype' ) ;
4342
+
4343
+ function TestController ( ) {
4344
+ return { $onChanges : constructorSpy } ;
4345
+ }
4346
+ TestController . prototype . $onChanges = prototypeSpy ;
4347
+
4348
+ module ( function ( $compileProvider ) {
4349
+ $compileProvider . component ( 'test' , {
4350
+ bindings : { attr : '@' } ,
4351
+ controller : TestController
4352
+ } ) ;
4353
+ } ) ;
4354
+
4355
+ inject ( function ( $compile , $rootScope ) {
4356
+ var template = '<test attr="{{a}}"></test>' ;
4357
+ $rootScope . a = 'foo' ;
4358
+
4359
+ element = $compile ( template ) ( $rootScope ) ;
4360
+ $rootScope . $digest ( ) ;
4361
+ expect ( constructorSpy ) . toHaveBeenCalled ( ) ;
4362
+ expect ( prototypeSpy ) . not . toHaveBeenCalled ( ) ;
4363
+
4364
+ constructorSpy . calls . reset ( ) ;
4365
+ $rootScope . $apply ( 'a = "bar"' ) ;
4366
+ expect ( constructorSpy ) . toHaveBeenCalled ( ) ;
4367
+ expect ( prototypeSpy ) . not . toHaveBeenCalled ( ) ;
4368
+ } ) ;
4369
+ } ) ;
4339
4370
4340
4371
it ( 'should not call `$onChanges` twice even when the initial value is `NaN`' , function ( ) {
4341
4372
var onChangesSpy = jasmine . createSpy ( '$onChanges' ) ;
You can’t perform that action at this time.
0 commit comments