|
271 | 271 | *
|
272 | 272 | * #### `require`
|
273 | 273 | * Require another directive and inject its controller as the fourth argument to the linking function. The
|
274 |
| - * `require` takes a string name (or array of strings) of the directive(s) to pass in. If an array is used, the |
275 |
| - * injected argument will be an array in corresponding order. If no such directive can be |
276 |
| - * found, or if the directive does not have a controller, then an error is raised (unless no link function |
277 |
| - * is specified, in which case error checking is skipped). The name can be prefixed with: |
| 274 | + * `require` property can be a string, an array or an object: |
| 275 | + * * a **string** containing the name of the directive to pass to the linking function |
| 276 | + * * an **array** containing the names of directives to pass to the linking function. The argument passed to the |
| 277 | + * linking function will be an array of controllers in the same order as the names in the `require` property |
| 278 | + * * an **object** whose property values are the names of the directives to pass to the linking function. The argument |
| 279 | + * passed to the linking function will also be an object with matching keys, whose values will hold the corresponding |
| 280 | + * controllers. |
| 281 | + * |
| 282 | + * If no such directive(s) can be found, or if the directive does not have a controller, then an error is raised |
| 283 | + * (unless no link function is specified, in which case error checking is skipped). The name can be prefixed with: |
278 | 284 | *
|
279 | 285 | * * (no prefix) - Locate the required controller on the current element. Throw an error if not found.
|
280 | 286 | * * `?` - Attempt to locate the required controller or pass `null` to the `link` fn if not found.
|
@@ -2308,6 +2314,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
2308 | 2314 | for (var i = 0, ii = require.length; i < ii; i++) {
|
2309 | 2315 | value[i] = getControllers(directiveName, require[i], $element, elementControllers);
|
2310 | 2316 | }
|
| 2317 | + } else if (isObject(require)) { |
| 2318 | + value = {}; |
| 2319 | + forEach(require, function(controller, property) { |
| 2320 | + value[property] = getControllers(directiveName, controller, $element, elementControllers); |
| 2321 | + }); |
2311 | 2322 | }
|
2312 | 2323 |
|
2313 | 2324 | return value || null;
|
@@ -2414,6 +2425,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
2414 | 2425 | removeControllerBindingWatches =
|
2415 | 2426 | initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
|
2416 | 2427 | }
|
| 2428 | + |
| 2429 | + if (isObject(controllerDirective.require) && !isArray(controllerDirective.require)) { |
| 2430 | + var controllers = getControllers(name, controllerDirective.require, $element, elementControllers); |
| 2431 | + console.log(controllers); |
| 2432 | + } |
2417 | 2433 | }
|
2418 | 2434 |
|
2419 | 2435 | // Trigger the `$onInit` method on all controllers that have one
|
|
0 commit comments