This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -393,7 +393,7 @@ function $RootScopeProvider(){
393
393
watch = watchers [ length ] ;
394
394
// Most common watches are on primitives, in which case we can short
395
395
// circuit it with === operator, only when === fails do we use .equals
396
- if ( ( value = watch . get ( current ) ) !== ( last = watch . last ) &&
396
+ if ( watch && ( value = watch . get ( current ) ) !== ( last = watch . last ) &&
397
397
! ( watch . eq
398
398
? equals ( value , last )
399
399
: ( typeof value == 'number' && typeof last == 'number'
Original file line number Diff line number Diff line change @@ -318,6 +318,30 @@ describe('Scope', function() {
318
318
expect ( listener ) . not . toHaveBeenCalled ( ) ;
319
319
} ) ) ;
320
320
321
+ it ( 'should allow a watch to be unregistered while in a digest' , inject ( function ( $rootScope ) {
322
+ var remove1 , remove2 ;
323
+ $rootScope . $watch ( 'remove' , function ( ) {
324
+ remove1 ( ) ;
325
+ remove2 ( ) ;
326
+ } ) ;
327
+ remove1 = $rootScope . $watch ( 'thing' , function ( ) { } ) ;
328
+ remove2 = $rootScope . $watch ( 'thing' , function ( ) { } ) ;
329
+ expect ( function ( ) {
330
+ $rootScope . $apply ( 'remove = true' ) ;
331
+ } ) . not . toThrow ( ) ;
332
+ } ) ) ;
333
+
334
+ it ( 'should allow a watch to be added while in a digest' , inject ( function ( $rootScope ) {
335
+ var watch1 = jasmine . createSpy ( 'watch1' ) ,
336
+ watch2 = jasmine . createSpy ( 'watch2' ) ;
337
+ $rootScope . $watch ( 'foo' , function ( ) {
338
+ $rootScope . $watch ( 'foo' , watch1 ) ;
339
+ $rootScope . $watch ( 'foo' , watch2 ) ;
340
+ } ) ;
341
+ $rootScope . $apply ( 'foo = true' ) ;
342
+ expect ( watch1 ) . toHaveBeenCalled ( ) ;
343
+ expect ( watch2 ) . toHaveBeenCalled ( ) ;
344
+ } ) ) ;
321
345
322
346
it ( 'should not infinitely digest when current value is NaN' , inject ( function ( $rootScope ) {
323
347
$rootScope . $watch ( function ( ) { return NaN ; } ) ;
You can’t perform that action at this time.
0 commit comments