mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-26 13:05:35 +08:00
fix($parse): stabilize one-time literal expressions correctly
Change `oneTimeLiteralWatchDelegate` to use the last value in the digest cycle to check if the literal value is stable
This commit is contained in:
committed by
Lucas Galfaso
parent
57f804a4ed
commit
874cac825b
@@ -1301,6 +1301,28 @@ describe('parser', function() {
|
||||
expect($rootScope.$$watchers.length).toBe(0);
|
||||
expect(log.empty()).toEqual([]);
|
||||
}));
|
||||
|
||||
it('should only become stable when all the elements of an array have defined values at the end of a $digest', inject(function($parse, $rootScope, log) {
|
||||
var fn = $parse('::[foo]');
|
||||
$rootScope.$watch(fn, function(value) { log(value); }, true);
|
||||
$rootScope.$watch('foo', function() { if ($rootScope.foo === 'bar') {$rootScope.foo = undefined; } });
|
||||
|
||||
$rootScope.foo = 'bar';
|
||||
$rootScope.$digest();
|
||||
expect($rootScope.$$watchers.length).toBe(2);
|
||||
expect(log.empty()).toEqual([['bar'], [undefined]]);
|
||||
|
||||
$rootScope.foo = 'baz';
|
||||
$rootScope.$digest();
|
||||
expect($rootScope.$$watchers.length).toBe(1);
|
||||
expect(log.empty()).toEqual([['baz']]);
|
||||
|
||||
$rootScope.bar = 'qux';
|
||||
$rootScope.$digest();
|
||||
expect($rootScope.$$watchers.length).toBe(1);
|
||||
expect(log).toEqual([]);
|
||||
}));
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user