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

Commit e7ac08a

Browse files
committed
fix($compile): update '@'-bindings in controller when bindToController is true
'@'-bindings were previously updating the scope when they ought to have been updating the controller (requested via `bindToController: true` + controllerAs). It's a one-line fix + test case. Closes #9052 Closes #9077
1 parent 7ffe524 commit e7ac08a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
16971697

16981698
case '@':
16991699
attrs.$observe(attrName, function(value) {
1700-
isolateScope[scopeName] = value;
1700+
isolateBindingContext[scopeName] = value;
17011701
});
17021702
attrs.$$observers[attrName].$$scope = scope;
17031703
if( attrs[attrName] ) {

test/ng/compileSpec.js

+26
Original file line numberDiff line numberDiff line change
@@ -3567,6 +3567,32 @@ describe('$compile', function() {
35673567
});
35683568

35693569

3570+
it('should update @-bindings on controller when bindToController and attribute change observed', function(){
3571+
module(function($compileProvider) {
3572+
$compileProvider.directive('atBinding', valueFn({
3573+
template: '<p>{{At.text}}</p>',
3574+
scope: {
3575+
text: '@atBinding'
3576+
},
3577+
controller: function($scope) {},
3578+
bindToController: true,
3579+
controllerAs: 'At'
3580+
}));
3581+
});
3582+
3583+
inject(function($compile, $rootScope) {
3584+
element = $compile('<div at-binding="Test: {{text}}"></div>')($rootScope);
3585+
var p = element.find('p');
3586+
$rootScope.$digest();
3587+
expect(p.text()).toBe('Test: ');
3588+
3589+
$rootScope.text = 'Kittens';
3590+
$rootScope.$digest();
3591+
expect(p.text()).toBe('Test: Kittens');
3592+
});
3593+
});
3594+
3595+
35703596
it('should expose isolate scope variables on controller with controllerAs when bindToController is true', function() {
35713597
var controllerCalled = false;
35723598
module(function($compileProvider) {

0 commit comments

Comments
 (0)