You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Behaviour bindToController in child scope versus isolated scope #13021
The changes to name are forwarded to the child scope, but not to the parent scope. This in contrast to binding to an isolated scope, where the changes are forwarded to the old scope. Why is this?
I believe this is a valid bug. When using bindToController = {...} with scope: true, we are evaluating the directive's bindings against the new (child) scope, instead of the parent scope.
(I think it's an oversight, because of the "post-mortem" backporting of bindToController to non-isolate scopes - it was a bug we've been getting away with, because of JS's prototypal inheritance, but it makes itself felt when using properties with the same name on both scopes (e.g. controller aliases).)
Working on a fix (I think)...
BTW, here is a failing testcase:
it('should evaluate against the correct scope, when using `bindToController` (new scope)',function(){module(function($compileProvider,$controllerProvider){$controllerProvider.register({'ParentCtrl': function(){this.value='parent';},'ChildCtrl': function(){this.value='child';}});$compileProvider.directive('child',valueFn({scope: true,controller: 'ChildCtrl',controllerAs: 'ctrl',bindToController: {value2: '='},template: '{{ ctrl.value2 }}'}));});inject(function($compile,$rootScope){element=$compile('<div ng-controller="ParentCtrl as ctrl">'+'<child value2="ctrl.value"></child>'+'</div>')($rootScope);$rootScope.$digest();expect(element.text()).toBe('parent');});});
Activity
gkalpak commentedon Oct 6, 2015
I believe this is a valid bug. When using
bindToController = {...}withscope: true, we are evaluating the directive's bindings against the new (child) scope, instead of the parent scope.(I think it's an oversight, because of the "post-mortem" backporting of
bindToControllerto non-isolate scopes - it was a bug we've been getting away with, because of JS's prototypal inheritance, but it makes itself felt when using properties with the same name on both scopes (e.g. controller aliases).)Working on a fix (I think)...
BTW, here is a failing testcase:
fix($compile): evaluate against the correct scope with bindToControll…
jwgmeligmeyling commentedon Oct 6, 2015
👍
fix($compile): evaluate against the correct scope with bindToControll…
fix($compile): evaluate against the correct scope with bindToControll…
fix($compile): evaluate against the correct scope with bindToControll…
fix($compile): evaluate against the correct scope with bindToControll…
Update AngularJS