fix($compile): do not overwrite values set in $onInit() for <-bound literals
See #15118 for more details. Fixes #15118 Closes #15123
This commit is contained in:
+5
-2
@@ -3506,18 +3506,21 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
||||
if (optional && !attrs[attrName]) break;
|
||||
|
||||
parentGet = $parse(attrs[attrName]);
|
||||
var deepWatch = parentGet.literal;
|
||||
|
||||
var initialValue = destination[scopeName] = parentGet(scope);
|
||||
initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]);
|
||||
|
||||
removeWatch = scope.$watch(parentGet, function parentValueWatchAction(newValue, oldValue) {
|
||||
if (oldValue === newValue) {
|
||||
if (oldValue === initialValue) return;
|
||||
if (oldValue === initialValue || (deepWatch && equals(oldValue, initialValue))) {
|
||||
return;
|
||||
}
|
||||
oldValue = initialValue;
|
||||
}
|
||||
recordChanges(scopeName, newValue, oldValue);
|
||||
destination[scopeName] = newValue;
|
||||
}, parentGet.literal);
|
||||
}, deepWatch);
|
||||
|
||||
removeWatchCollection.push(removeWatch);
|
||||
break;
|
||||
|
||||
+32
-1
@@ -5524,7 +5524,7 @@ describe('$compile', function() {
|
||||
expect($rootScope.name).toEqual('outer');
|
||||
expect(component.input).toEqual('$onInit');
|
||||
|
||||
$rootScope.$apply();
|
||||
$rootScope.$digest();
|
||||
|
||||
expect($rootScope.name).toEqual('outer');
|
||||
expect(component.input).toEqual('$onInit');
|
||||
@@ -5537,6 +5537,37 @@ describe('$compile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not update isolate again after $onInit if outer is a literal', function() {
|
||||
module('owComponentTest');
|
||||
inject(function() {
|
||||
$rootScope.name = 'outer';
|
||||
compile('<ow-component input="[name]"></ow-component>');
|
||||
|
||||
expect(component.input).toEqual('$onInit');
|
||||
|
||||
// No outer change
|
||||
$rootScope.$apply('name = "outer"');
|
||||
expect(component.input).toEqual('$onInit');
|
||||
|
||||
// Outer change
|
||||
$rootScope.$apply('name = "re-outer"');
|
||||
expect(component.input).toEqual(['re-outer']);
|
||||
|
||||
expect(log).toEqual([
|
||||
'constructor',
|
||||
[
|
||||
'$onChanges',
|
||||
jasmine.objectContaining({currentValue: ['outer']})
|
||||
],
|
||||
'$onInit',
|
||||
[
|
||||
'$onChanges',
|
||||
jasmine.objectContaining({previousValue: ['outer'], currentValue: ['re-outer']})
|
||||
]
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should update isolate again after $onInit if outer has changed (before initial watchAction call)', function() {
|
||||
module('owComponentTest');
|
||||
inject(function() {
|
||||
|
||||
Reference in New Issue
Block a user