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

Commit

Permalink
fix($compile): reference local in isolate scope
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vojtajina committed Sep 21, 2012
1 parent bcaa3bb commit 8db47ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ function $CompileProvider($provide) {
lastValue = scope[scopeName] = parentValue;
} else {
// if the parent can be assigned then do so
parentSet(parentScope, lastValue = scope[scopeName]);
parentSet(parentScope, parentValue = lastValue = scope[scopeName]);
}
}
return parentValue;
Expand Down
19 changes: 19 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,7 @@ describe('$compile', function() {
attrAlias: '@attr',
ref: '=',
refAlias: '= ref',
reference: '=',
expr: '&',
exprAlias: '&expr'
},
Expand Down Expand Up @@ -1830,6 +1831,24 @@ describe('$compile', function() {
$rootScope.$apply();
expect(componentScope.ref).toBe('hello misko');
}));

// regression
it('should stabilize model', inject(function() {
compile('<div><span my-component reference="name">');

var lastRefValueInParent;
$rootScope.$watch('name', function(ref) {
lastRefValueInParent = ref;
});

$rootScope.name = 'aaa';
$rootScope.$apply();

componentScope.reference = 'new';
$rootScope.$apply();

expect(lastRefValueInParent).toBe('new');
}));
});


Expand Down

0 comments on commit 8db47ca

Please sign in to comment.