* @ngdoc provider * @name $controllerProvider * @this * * @description * The ng.$controller $controller service is used by AngularJS to create new * controllers. * * This provider allows controller registration via the * ng.$controllerProvider#register register method.
()
| 11594 | * {@link ng.$controllerProvider#register register} method. |
| 11595 | */ |
| 11596 | function $ControllerProvider() { |
| 11597 | var controllers = {}; |
| 11598 | |
| 11599 | /** |
| 11600 | * @ngdoc method |
| 11601 | * @name $controllerProvider#has |
| 11602 | * @param {string} name Controller name to check. |
| 11603 | */ |
| 11604 | this.has = function(name) { |
| 11605 | return controllers.hasOwnProperty(name); |
| 11606 | }; |
| 11607 | |
| 11608 | /** |
| 11609 | * @ngdoc method |
| 11610 | * @name $controllerProvider#register |
| 11611 | * @param {string|Object} name Controller name, or an object map of controllers where the keys are |
| 11612 | * the names and the values are the constructors. |
| 11613 | * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI |
| 11614 | * annotations in the array notation). |
| 11615 | */ |
| 11616 | this.register = function(name, constructor) { |
| 11617 | assertNotHasOwnProperty(name, 'controller'); |
| 11618 | if (isObject(name)) { |
| 11619 | extend(controllers, name); |
| 11620 | } else { |
| 11621 | controllers[name] = constructor; |
| 11622 | } |
| 11623 | }; |
| 11624 | |
| 11625 | this.$get = ['$injector', function($injector) { |
| 11626 | |
| 11627 | /** |
| 11628 | * @ngdoc service |
| 11629 | * @name $controller |
| 11630 | * @requires $injector |
| 11631 | * |
| 11632 | * @param {Function|string} constructor If called with a function then it's considered to be the |
| 11633 | * controller constructor function. Otherwise it's considered to be a string which is used |
| 11634 | * to retrieve the controller constructor using the following steps: |
| 11635 | * |
| 11636 | * * check if a controller with given name is registered via `$controllerProvider` |
| 11637 | * * check if evaluating the string on the current scope returns a constructor |
| 11638 | * |
| 11639 | * The string can use the `controller as property` syntax, where the controller instance is published |
| 11640 | * as the specified property on the `scope`; the `scope` must be injected into `locals` param for this |
| 11641 | * to work correctly. |
| 11642 | * |
| 11643 | * @param {Object} locals Injection locals for Controller. |
| 11644 | * @return {Object} Instance of given controller. |
| 11645 | * |
| 11646 | * @description |
| 11647 | * `$controller` service is responsible for instantiating controllers. |
| 11648 | * |
| 11649 | * It's just a simple call to {@link auto.$injector $injector}, but extracted into |
| 11650 | * a service, so that one can override this service with [BC version](https://gist.github.com/1649788). |
| 11651 | */ |
| 11652 | return function $controller(expression, locals, later, ident) { |
| 11653 | // PRIVATE API: |
nothing calls this directly
no test coverage detected