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
This commit is contained in:
Caitlin Potter
2014-09-14 10:04:26 -04:00
parent 7ffe524171
commit e7ac08a061
2 changed files with 27 additions and 1 deletions

View File

@@ -1697,7 +1697,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
case '@':
attrs.$observe(attrName, function(value) {
isolateScope[scopeName] = value;
isolateBindingContext[scopeName] = value;
});
attrs.$$observers[attrName].$$scope = scope;
if( attrs[attrName] ) {

View File

@@ -3567,6 +3567,32 @@ describe('$compile', function() {
});
it('should update @-bindings on controller when bindToController and attribute change observed', function(){
module(function($compileProvider) {
$compileProvider.directive('atBinding', valueFn({
template: '<p>{{At.text}}</p>',
scope: {
text: '@atBinding'
},
controller: function($scope) {},
bindToController: true,
controllerAs: 'At'
}));
});
inject(function($compile, $rootScope) {
element = $compile('<div at-binding="Test: {{text}}"></div>')($rootScope);
var p = element.find('p');
$rootScope.$digest();
expect(p.text()).toBe('Test: ');
$rootScope.text = 'Kittens';
$rootScope.$digest();
expect(p.text()).toBe('Test: Kittens');
});
});
it('should expose isolate scope variables on controller with controllerAs when bindToController is true', function() {
var controllerCalled = false;
module(function($compileProvider) {