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

Commit 8db47ca

Browse files
committed
fix($compile): reference local in isolate scope
This was really corner case: Watcher needs to return changed value, to notify that model might have changed and one more $digest cycle needs to be performed. The watcher, that takes care of reference binding into an isolate scope ("="), did not return changed value, if the change was from the isolate scope to the parent. If any other watcher returned change, it worked fine, as this change caused re-digest. Closes #1272
1 parent bcaa3bb commit 8db47ca

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ function $CompileProvider($provide) {
747747
lastValue = scope[scopeName] = parentValue;
748748
} else {
749749
// if the parent can be assigned then do so
750-
parentSet(parentScope, lastValue = scope[scopeName]);
750+
parentSet(parentScope, parentValue = lastValue = scope[scopeName]);
751751
}
752752
}
753753
return parentValue;

test/ng/compileSpec.js

+19
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,7 @@ describe('$compile', function() {
17091709
attrAlias: '@attr',
17101710
ref: '=',
17111711
refAlias: '= ref',
1712+
reference: '=',
17121713
expr: '&',
17131714
exprAlias: '&expr'
17141715
},
@@ -1830,6 +1831,24 @@ describe('$compile', function() {
18301831
$rootScope.$apply();
18311832
expect(componentScope.ref).toBe('hello misko');
18321833
}));
1834+
1835+
// regression
1836+
it('should stabilize model', inject(function() {
1837+
compile('<div><span my-component reference="name">');
1838+
1839+
var lastRefValueInParent;
1840+
$rootScope.$watch('name', function(ref) {
1841+
lastRefValueInParent = ref;
1842+
});
1843+
1844+
$rootScope.name = 'aaa';
1845+
$rootScope.$apply();
1846+
1847+
componentScope.reference = 'new';
1848+
$rootScope.$apply();
1849+
1850+
expect(lastRefValueInParent).toBe('new');
1851+
}));
18331852
});
18341853

18351854

0 commit comments

Comments
 (0)