This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$onInit
and friends
#13763
Closed
Closed
$onInit
and friends
#13763
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
50b0c1a
feat($compile): call `$ngOnInit` on directive controllers after contr…
petebacondarwin cf4e7be
test($compile): check that $onInit is called correctly for ES6 classes
petebacondarwin 452dd39
docs($compile): document the new `$onInit` controller hook
petebacondarwin f72ecbd
feat($compile): allow `require` to be an object
petebacondarwin b2c0b05
feat($compile): allow required controllers to be bound to the directi…
petebacondarwin 37793ce
feat($compile): allow `require` to be an object
petebacondarwin a12ddc6
test($compile): check explicit return controllers are not broken by b…
petebacondarwin 59feecc
feat($compile): allow required controllers to be bound to the directi…
petebacondarwin 8040bab
feat($compile): call `$ngOnInit` on directive controllers after contr…
petebacondarwin 9e6db1a
feat($compile): allow required controllers to be bound to the directi…
petebacondarwin 1d18df2
fix($compile): ensure controllers with return value constructors are …
petebacondarwin 4b304a6
docs($compile): squash me
petebacondarwin cae40ca
fix($compile): only bind required controllers if `bindToController` i…
petebacondarwin 276b9ee
docs($compile): fix typo
petebacondarwin 6d66a75
fix($compile): only bind required controllers if `bindToController` i…
petebacondarwin 32b7da3
test($compile): check that $onInit is called correctly for ES6 classes
petebacondarwin cb495a5
fix($compile): only bind required controllers if `bindToController` i…
petebacondarwin 270e230
fix($compile): ensure controllers with return value constructors are …
petebacondarwin 281d987
fix($compile): only bind required controllers if `bindToController` i…
petebacondarwin 9f76a11
test($compile): check that $onInit is called correctly for ES6 classes
petebacondarwin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat($compile): allow
require
to be an object
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.
- Loading branch information
commit f72ecbd48ddc02ee0ba3c39fa0e36e80e7655394
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,10 +271,16 @@ | |
* | ||
* #### `require` | ||
* Require another directive and inject its controller as the fourth argument to the linking function. The | ||
* `require` takes a string name (or array of strings) of the directive(s) to pass in. If an array is used, the | ||
* injected argument will be an array in corresponding order. If no such directive can be | ||
* found, or if the directive does not have a controller, then an error is raised (unless no link function | ||
* is specified, in which case error checking is skipped). The name can be prefixed with: | ||
* `require` property can be a string, an array or an object: | ||
* * 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 | ||
* passed to the linking function will also be an object with matching keys, whose values will be the corresponding | ||
* controller. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. controller --> controllers (?) |
||
* | ||
* If no such directive(s) can be found, or if the directive does not have a controller, then an error is raised | ||
* (unless no link function is specified, in which case error checking is skipped). The name can be prefixed with: | ||
* | ||
* * (no prefix) - Locate the required controller on the current element. Throw an error if not found. | ||
* * `?` - Attempt to locate the required controller or pass `null` to the `link` fn if not found. | ||
|
@@ -2295,6 +2301,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |
for (var i = 0, ii = require.length; i < ii; i++) { | ||
value[i] = getControllers(directiveName, require[i], $element, elementControllers); | ||
} | ||
} else if (isObject(require)) { | ||
value = {}; | ||
forEach(require, function(controller, property) { | ||
value[property] = getControllers(directiveName, controller, $element, elementControllers); | ||
}); | ||
} | ||
|
||
return value || null; | ||
|
@@ -2401,6 +2412,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |
removeControllerBindingWatches = | ||
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective); | ||
} | ||
|
||
if (isObject(controllerDirective.require) && !isArray(controllerDirective.require)) { | ||
var controllers = getControllers(name, controllerDirective.require, $element, elementControllers); | ||
console.log(controllers); | ||
} | ||
} | ||
|
||
// Trigger the `$onInit` method on all controllers that have one | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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