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

Function $ControllerProvider

test/angular/1.3/angular.js:8403–8543  ·  view source on GitHub ↗

* @ngdoc provider * @name $controllerProvider * @description * The ng.$controller $controller service is used by Angular to create new * controllers. * * This provider allows controller registration via the * ng.$controllerProvider#register register method.

()

Source from the content-addressed store, hash-verified

8401 * {@link ng.$controllerProvider#register register} method.
8402 */
8403function $ControllerProvider() {
8404 var controllers = {},
8405 globals = false,
8406 CNTRL_REG = /^(\S+)(\s+as\s+(\w+))?$/;
8407
8408
8409 /**
8410 * @ngdoc method
8411 * @name $controllerProvider#register
8412 * @param {string|Object} name Controller name, or an object map of controllers where the keys are
8413 * the names and the values are the constructors.
8414 * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI
8415 * annotations in the array notation).
8416 */
8417 this.register = function(name, constructor) {
8418 assertNotHasOwnProperty(name, 'controller');
8419 if (isObject(name)) {
8420 extend(controllers, name);
8421 } else {
8422 controllers[name] = constructor;
8423 }
8424 };
8425
8426 /**
8427 * @ngdoc method
8428 * @name $controllerProvider#allowGlobals
8429 * @description If called, allows `$controller` to find controller constructors on `window`
8430 */
8431 this.allowGlobals = function() {
8432 globals = true;
8433 };
8434
8435
8436 this.$get = ['$injector', '$window', function($injector, $window) {
8437
8438 /**
8439 * @ngdoc service
8440 * @name $controller
8441 * @requires $injector
8442 *
8443 * @param {Function|string} constructor If called with a function then it's considered to be the
8444 * controller constructor function. Otherwise it's considered to be a string which is used
8445 * to retrieve the controller constructor using the following steps:
8446 *
8447 * * check if a controller with given name is registered via `$controllerProvider`
8448 * * check if evaluating the string on the current scope returns a constructor
8449 * * if $controllerProvider#allowGlobals, check `window[constructor]` on the global
8450 * `window` object (not recommended)
8451 *
8452 * The string can use the `controller as property` syntax, where the controller instance is published
8453 * as the specified property on the `scope`; the `scope` must be injected into `locals` param for this
8454 * to work correctly.
8455 *
8456 * @param {Object} locals Injection locals for Controller.
8457 * @return {Object} Instance of given controller.
8458 *
8459 * @description
8460 * `$controller` service is responsible for instantiating controllers.

Callers

nothing calls this directly

Calls 9

isArrayFunction · 0.85
matchMethod · 0.80
assertNotHasOwnPropertyFunction · 0.70
isObjectFunction · 0.70
extendFunction · 0.70
isStringFunction · 0.70
getterFunction · 0.70
assertArgFnFunction · 0.70
addIdentifierFunction · 0.70

Tested by

no test coverage detected