|
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 directibes 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 be the corresponding |
| 280 | + * controller. |
| 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.
|
@@ -2295,6 +2301,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
2295 | 2301 | for (var i = 0, ii = require.length; i < ii; i++) {
|
2296 | 2302 | value[i] = getControllers(directiveName, require[i], $element, elementControllers);
|
2297 | 2303 | }
|
| 2304 | + } else if (isObject(require)) { |
| 2305 | + value = {}; |
| 2306 | + forEach(require, function(controller, property) { |
| 2307 | + value[property] = getControllers(directiveName, controller, $element, elementControllers); |
| 2308 | + }); |
2298 | 2309 | }
|
2299 | 2310 |
|
2300 | 2311 | return value || null;
|
@@ -2401,6 +2412,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
2401 | 2412 | removeControllerBindingWatches =
|
2402 | 2413 | initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
|
2403 | 2414 | }
|
| 2415 | + |
| 2416 | + if (isObject(controllerDirective.require) && !isArray(controllerDirective.require)) { |
| 2417 | + var controllers = getControllers(name, controllerDirective.require, $element, elementControllers); |
| 2418 | + console.log(controllers); |
| 2419 | + } |
2404 | 2420 | }
|
2405 | 2421 |
|
2406 | 2422 | // Trigger the `$onInit` method on all controllers that have one
|
|
0 commit comments