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

1.3.0-rc.1 - isolate scope @ bindings not kept up to date when used with the bindToController directive property #9052

Closed
mragentman opened this issue Sep 12, 2014 · 4 comments

Comments

@mragentman
Copy link

When using the bindToController directive property of Angular 1.3.0-rc.1, the isolate scope properties which are bound using the '@' are set properly upon initialization but not kept up to date with subsequent changes.

I have put together a Plunkr to demonstrate the issue. The two-way binding instance, using '=' in the isolate scope, receives updates as the radio button is changed but the binding with '@' does not:
http://plnkr.co/edit/cZcz70UlfPRrHZjDWcto?p=preview

Looking at the Angular source, it seems like the case statement for '@' may be keeping the wrong property up to date when the attribute changes (lines 6943-6953 in nodeLinkFn):

case '@':
    attrs.$observe(attrName, function(value) {
      isolateScope[scopeName] = value;
    });
    attrs.$$observers[attrName].$$scope = scope;
    if( attrs[attrName] ) {
      // If the attribute has been provided then we trigger an interpolation to ensure
      // the value is there for use in the link fn
      isolateBindingContext[scopeName] = $interpolate(attrs[attrName])(scope);
    }
    break;

It looks like the observe should be updating isolateBindingContext instead of isolateScope so that it keeps the controller instance property up to date instead of the scope property.

@Narretz
Copy link
Contributor

Narretz commented Sep 14, 2014

@caitp Didn't you implement this? Can you have a look?

@caitp
Copy link
Contributor

caitp commented Sep 14, 2014

yeah, taking a look

@caitp
Copy link
Contributor

caitp commented Sep 14, 2014

Yeah, looks like a valid bug, it still sets the scope value when observing the attribute, rather than the isolateBindingContext --- I'll push a fix

@caitp
Copy link
Contributor

caitp commented Sep 14, 2014

It's pretty much a 1line fix + test, so @Narretz can I get you to review in a few minutes? thanks

caitp added a commit to caitp/angular.js that referenced this issue Sep 14, 2014
…r 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 angular#9052
@caitp caitp closed this as completed in e7ac08a Sep 14, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.