* @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.
()
| 9331 | * {@link ng.$controllerProvider#register register} method. |
| 9332 | */ |
| 9333 | function $ControllerProvider() { |
| 9334 | var controllers = {}, |
| 9335 | globals = false; |
| 9336 | |
| 9337 | /** |
| 9338 | * @ngdoc method |
| 9339 | * @name $controllerProvider#register |
| 9340 | * @param {string|Object} name Controller name, or an object map of controllers where the keys are |
| 9341 | * the names and the values are the constructors. |
| 9342 | * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI |
| 9343 | * annotations in the array notation). |
| 9344 | */ |
| 9345 | this.register = function(name, constructor) { |
| 9346 | assertNotHasOwnProperty(name, 'controller'); |
| 9347 | if (isObject(name)) { |
| 9348 | extend(controllers, name); |
| 9349 | } else { |
| 9350 | controllers[name] = constructor; |
| 9351 | } |
| 9352 | }; |
| 9353 | |
| 9354 | /** |
| 9355 | * @ngdoc method |
| 9356 | * @name $controllerProvider#allowGlobals |
| 9357 | * @description If called, allows `$controller` to find controller constructors on `window` |
| 9358 | */ |
| 9359 | this.allowGlobals = function() { |
| 9360 | globals = true; |
| 9361 | }; |
| 9362 | |
| 9363 | |
| 9364 | this.$get = ['$injector', '$window', function($injector, $window) { |
| 9365 | |
| 9366 | /** |
| 9367 | * @ngdoc service |
| 9368 | * @name $controller |
| 9369 | * @requires $injector |
| 9370 | * |
| 9371 | * @param {Function|string} constructor If called with a function then it's considered to be the |
| 9372 | * controller constructor function. Otherwise it's considered to be a string which is used |
| 9373 | * to retrieve the controller constructor using the following steps: |
| 9374 | * |
| 9375 | * * check if a controller with given name is registered via `$controllerProvider` |
| 9376 | * * check if evaluating the string on the current scope returns a constructor |
| 9377 | * * if $controllerProvider#allowGlobals, check `window[constructor]` on the global |
| 9378 | * `window` object (not recommended) |
| 9379 | * |
| 9380 | * The string can use the `controller as property` syntax, where the controller instance is published |
| 9381 | * as the specified property on the `scope`; the `scope` must be injected into `locals` param for this |
| 9382 | * to work correctly. |
| 9383 | * |
| 9384 | * @param {Object} locals Injection locals for Controller. |
| 9385 | * @return {Object} Instance of given controller. |
| 9386 | * |
| 9387 | * @description |
| 9388 | * `$controller` service is responsible for instantiating controllers. |
| 9389 | * |
| 9390 | * It's just a simple call to {@link auto.$injector $injector}, but extracted into |
nothing calls this directly
no test coverage detected