MCPcopy Index your code
hub / github.com/angular-ui/ui-router / getControllers

Function getControllers

test/angular/1.7/angular.js:10644–10693  ·  view source on GitHub ↗
(directiveName, require, $element, elementControllers)

Source from the content-addressed store, hash-verified

10642 }
10643
10644 function getControllers(directiveName, require, $element, elementControllers) {
10645 var value;
10646
10647 if (isString(require)) {
10648 var match = require.match(REQUIRE_PREFIX_REGEXP);
10649 var name = require.substring(match[0].length);
10650 var inheritType = match[1] || match[3];
10651 var optional = match[2] === '?';
10652
10653 //If only parents then start at the parent element
10654 if (inheritType === '^^') {
10655 $element = $element.parent();
10656 //Otherwise attempt getting the controller from elementControllers in case
10657 //the element is transcluded (and has no data) and to avoid .data if possible
10658 } else {
10659 value = elementControllers && elementControllers[name];
10660 value = value && value.instance;
10661 }
10662
10663 if (!value) {
10664 var dataName = '$' + name + 'Controller';
10665
10666 if (inheritType === '^^' && $element[0] && $element[0].nodeType === NODE_TYPE_DOCUMENT) {
10667 // inheritedData() uses the documentElement when it finds the document, so we would
10668 // require from the element itself.
10669 value = null;
10670 } else {
10671 value = inheritType ? $element.inheritedData(dataName) : $element.data(dataName);
10672 }
10673 }
10674
10675 if (!value && !optional) {
10676 throw $compileMinErr('ctreq',
10677 'Controller \'{0}\', required by directive \'{1}\', can\'t be found!',
10678 name, directiveName);
10679 }
10680 } else if (isArray(require)) {
10681 value = [];
10682 for (var i = 0, ii = require.length; i < ii; i++) {
10683 value[i] = getControllers(directiveName, require[i], $element, elementControllers);
10684 }
10685 } else if (isObject(require)) {
10686 value = {};
10687 forEach(require, function(controller, property) {
10688 value[property] = getControllers(directiveName, controller, $element, elementControllers);
10689 });
10690 }
10691
10692 return value || null;
10693 }
10694
10695 function setupControllers($element, attrs, transcludeFn, controllerDirectives, isolateScope, scope, newIsolateScopeDirective) {
10696 var elementControllers = createMap();

Callers 1

nodeLinkFnFunction · 0.70

Calls 5

isArrayFunction · 0.85
matchMethod · 0.80
isStringFunction · 0.70
isObjectFunction · 0.70
forEachFunction · 0.70

Tested by

no test coverage detected