-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Conversation
* * a **string** containing the name of the directive to pass to the linking function | ||
* * an **array** containing the names of directives to pass to the linking function. The argument passed to the | ||
* linking function will be an array of controllers in the same order as the names in the `require` property | ||
* * an **object** whose property values are the names of the directibes to pass to the linking function. The argument |
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.
directibes --> directives
With the exception of #13763 (comment) (and a couple of nitpicks), this L(pretty)GTM 👍 |
@@ -4244,6 +4244,22 @@ describe('$compile', function() { | |||
if (!/chrome/i.test(navigator.userAgent)) return; |
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.
unrelated to this issue, but can we change this to if (!support.classes) return;
?
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.
On it [sic]!
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.
Actually, it is not so easy @lgalfaso since the latest Safari (9.0.2) is even worse for toString
on a a class instance.
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.
it looks like there are at least 2 issues reported on JavascriptCore (Safari JS engine) regarding this
https://bugs.webkit.org/show_bug.cgi?id=149743
https://bugs.webkit.org/show_bug.cgi?id=144285
I think that some other strategy. Meanwhile, just keep the old code
…oller construction This enables option three of angular#13510 (comment) by allowing the creator of directive controllers using ES6 classes to have a hook that is called when the bindings are definitely available. Moreover this will help solve the problem of accessing `require`d controllers from controller instances without resorting to wiring up in a `link` function. See angular#5893
This provides an elegant alternative to the array form of the `require` property but also helps to support binding of `require`d controllers to directive controllers.
…ve controller If directives are required through an object hash, rather than a string or array, the required directives' controllers are bound to the current directive's controller in much the same way as the properties are bound to using `bindToController`. The binding is done after the controller has been constructed and all the bindings are guaranteed to be complete by the time the controller's `$onInit` method is called. This change makes it much simpler to access require controllers without the need for manually wiring them up in link functions. In particular this enables support for `require` in directives defined using `mod.component()`
This provides an elegant alternative to the array form of the `require` property but also helps to support binding of `require`d controllers to directive controllers.
…ve controller If directives are required through an object hash, rather than a string or array, the required directives' controllers are bound to the current directive's controller in much the same way as the properties are bound to using `bindToController`. The binding is done after the controller has been constructed and all the bindings are guaranteed to be complete by the time the controller's `$onInit` method is called. This change makes it much simpler to access require controllers without the need for manually wiring them up in link functions. In particular this enables support for `require` in directives defined using `mod.component()`
…oller construction This enables option three of angular#13510 (comment) by allowing the creator of directive controllers using ES6 classes to have a hook that is called when the bindings are definitely available. Moreover this will help solve the problem of accessing `require`d controllers from controller instances without resorting to wiring up in a `link` function. See angular#5893
…ve controller If directives are required through an object hash, rather than a string or array, the required directives' controllers are bound to the current directive's controller in much the same way as the properties are bound to using `bindToController`. The binding is done after the controller has been constructed and all the bindings are guaranteed to be complete by the time the controller's `$onInit` method is called. This change makes it much simpler to access require controllers without the need for manually wiring them up in link functions. In particular this enables support for `require` in directives defined using `mod.component()`
620baa7
to
9e6db1a
Compare
* | ||
* If the `require` property is an object and the directive provides a controller, then the required controllers are | ||
* bound to the controller using the keys of the `require` property. See the {@link $compileProvider#component} helper | ||
* for an example of how this can be used. |
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 note that the controllers are only available once $onInit has been called, no?
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.
Updated
Now that require can be an object, should we pass the ctrls as an object to the link function like described here: #8401? (Yes from me) |
…required correctly See angular#13763 (comment)
* is instantiated, the initial values of the isolate scope bindings will be available if the controller is not an ES6 class. | ||
* allow a component to have its properties bound to the controller, rather than to scope. | ||
* | ||
* After the controller is instantiated, the initial values of the isolate scope bindings will bound to the 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.
will bound --> will be? bound
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.
done
98dc205
to
cae40ca
Compare
@@ -4280,6 +4283,7 @@ describe('$compile', function() { | |||
element = $compile('<div foo-dir dir-data="remoteData" ' + | |||
'dir-str="Hello, {{whom}}!" ' + | |||
'dir-fn="fn()"></div>')($rootScope); | |||
expect(Controller.prototype.$onInit).toHaveBeenCalled(); | |||
element.data('$fooDirController').check(); |
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.
Isn't this redundant now ?
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! removed
I just noticed the component method doesn't accept the templateNamespace / multiElement property, is this intentional? |
require: { container: '^parent', friend: 'sibling' }, | ||
bindToController: true, | ||
controller: MeController, | ||
controllerAs: '$ctrl' |
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.
Two controllerAs
occurrences (where 1 would be sufficient).
…required correctly See angular#13763 (comment)
@Narretz - I think we should try to keep the component API as simple as possible. These two are fairly uncommon, right? If people really need them they can complain and we can add them later. |
@petebacondarwin Sounds good |
There's a real travis failure btw:
Although the test wasn't introduced by this PR. |
@Narretz I have fixed that failing test. |
70049ae
to
b77e14b
Compare
This looks very nice and clean. Should be like this from beggining. Very nice work. Do you think $onInit with bound required controllers and component() syntax will get on board with 1.5 release? I'd love to use it in production - it would clean up a lot of messy directive code. :-) |
…required correctly See angular#13763 (comment)
…ve controller If directives are required through an object hash, rather than a string or array, the required directives' controllers are bound to the current directive's controller in much the same way as the properties are bound to using `bindToController`. This only happens if `bindToController` is truthy. The binding is done after the controller has been constructed and all the bindings are guaranteed to be complete by the time the controller's `$onInit` method is called. This change makes it much simpler to access require controllers without the need for manually wiring them up in link functions. In particular this enables support for `require` in directives defined using `mod.component()` Closes #6040 Closes #5893 Closes #13763
that's the point.... fixes all fail... |
No description provided.