-
Couldn't load subscription status.
- Fork 27.3k
feat($compile): allow using bindToController as object, support both new/isolate scopes #10467
Conversation
|
CLAs look good, thanks! |
|
Why do you hate implying an isolate scope? Also, what are the goals of "bindToController"? For example, I'm trying to reconcile bindToController with the tabs example on the http://angularjs.org and using bindToController in conjunction with "require:'^tabs'" and a linking function bother me a bit. :/ (fyi, I'm working on a pull request to update the angularjs.org homepage examples) |
|
The goal of it is really just to make isolate scopes work better with |
|
Anyways, it's going to be a while before this (or something like it) lands, so it would be good to get some feedback on it, try it out and see how you like it, find bugs |
|
@caitp ok, thanks. So if the goal is "scopes work better with controllerAs", have you discussed: If a "controllerAs" is defined, imply that scope:{} bindings belong on that controller? That way you could remove bindToController completely... |
|
We can't really do that, it would be a breaking change |
|
Even for 1.4, it's too much of a break --- well, "too much of a break" --- it's more that Obviously, the directive api is stupidly complicated, and making it more complicated isn't helping anyone, so finding ways to simplify this would benefit everyone. But it's also a huge inconvenience due to breaking apps |
|
I think the primary goal is to move even more toward the way things will work in Angular 2 where we don't use scope directly for passing data to the template but instead attach stuff to the controller that is exposed on to the template - in 1.x this is via a scope but in 2 the controller instance is the scope |
|
neh, the rationale had nothing to do with v2, v2's prototype wasn't even as settled as it is now at that point. But that's not a very important thing -- the important thing is that people generally like controllerAs and want to use it, and want to be able to put their isolate scope bindings in the controller. |
|
@caitp and @petebacondarwin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this full name be more like: "controller as" identifier required to bind to controller?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not mitaken, this error will also be thrown if there is bindToController: true but no controler:.... So the literals have to account for all cases (i.e. bindToController: true but no controller or no controller identifier).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I see that now. I was thrown by the main body of the error document, which doesn't really mention that aspect of the error at all.
I wonder if we ought to have two separate errors?
|
Apart from splitting the error message, this looks good to me. @gkalpak do you have any further comments. |
|
👍 for separate error messages. |
|
if you want to release this today, i'll split up the error message and do whatever other cleanup in about 30 minutes. |
|
updated to have 2 different errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
directive definition object
|
@caitp - can you take a look at the comments here and update this PR? Thanks |
|
I don't think we should be calling it "alias", because it's misleading --- so I'm just going to ignore all of the comments about renaming "identifier" to "alias" |
|
@caitp - it is fine for you not to think we should not call it alias. As I explained in this comment, what we do need is consistency. I assume that your preferred name is |
|
@caitp |
…new/isolate scopes
bindToController is now able to be specified as a convenient object notation:
```
bindToController: {
text: '@text',
obj: '=obj',
expr: '&expr'
},
scope: {}
```
It can also be used in conjunction with new scopes, rather than exclusively isolate scopes:
```
bindToController: {
text: '@text',
obj: '=obj',
expr: '&expr'
},
scope: true
```
Closes angular#10420
The return value of the controller constructor is now respected in all cases. If controllerAs is used, the controller will be re-bound to scope. If bindToController is used, the previous binding $watches (if any) will be unwatched, and bindings re-installed on the new controller.
Clarify that these aliases are identifier names used to reference the controller.
|
this is ready to merge |
|
Great! LGTM! Thanks @caitp. I will merge tomorrow unless you want to do it today. |
|
I've got it, thanks for reviewing |
bindToController is now able to be specified as a convenient object notation:
It can also be used in conjunction with new scopes, rather than exclusively isolate scopes:
PING @petebacondarwin / @johnlindquist
I am not super keen on this, because it makes things much crazier than they used to be. That said:
bindToControllerdoes not automatically imply an isolate scope --- maybe it should (I hate this though)Closes #10420