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

controllerAs and returning scope properties no longer working #9073

Closed
EliotVU opened this issue Sep 14, 2014 · 2 comments
Closed

controllerAs and returning scope properties no longer working #9073

EliotVU opened this issue Sep 14, 2014 · 2 comments

Comments

@EliotVU
Copy link

EliotVU commented Sep 14, 2014

Since I updated my angular project from ~1.3 beta 17 to 1.3 rc.1 the controllerAs behavior is no longer working as expected, I am not sure if this is due an intended change, but I couldn't find any breaking changes in the changelog in relation to controllerAs, so being unsure I'll describe this issue just in case that it is indeed a bug.

Scenario:

  1. Have a directive with a controller and controllerAs ("Dock") property.
  2. Instead of using this.myFn = function(){}; I'm using:
    var stuff = {
    myFn: function(){}
    };
    return stuff;
  3. Logging the scope appears empty with the only property being "Dock", also empty.
  4. Have a link function in the directive accessing the scope like: scope.myFn(); = undefined.

Expected scope:
{
Dock: {
myFn : function(){}
}
}

To make myself clear, this worked just fine in (1.3 beta 17 IIRC).

Workaround:
In controller use this.myFn = function(){};
In link use this.Dock.myFn(); (worked as this.myFn even with controllerAs before update).

Expected behavior: returning an object from the controller function to work the same as adding a function to the "this" property.

@caitp
Copy link
Contributor

caitp commented Sep 14, 2014

the return value of controller constructors in directives is now ignored --- this was a breaking change, and is mentioned in the changelog, with suggested alternatives (sorry about the breaking change, there was no other way to do it --- we needed to make sure that we could get the controller instance before calling the constructor function, and the only way to do that is to allocate the controller instance ourselves and ignore the result of the constructor...)

@EliotVU
Copy link
Author

EliotVU commented Sep 14, 2014

Thanks for the explanation, shame to see this feature go, but nonetheless I have adapted my code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants