* @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.
()
| 9741 | * {@link ng.$controllerProvider#register register} method. |
| 9742 | */ |
| 9743 | function $ControllerProvider() { |
| 9744 | var controllers = {}, |
| 9745 | globals = false; |
| 9746 | |
| 9747 | /** |
| 9748 | * @ngdoc method |
| 9749 | * @name $controllerProvider#register |
| 9750 | * @param {string|Object} name Controller name, or an object map of controllers where the keys are |
| 9751 | * the names and the values are the constructors. |
| 9752 | * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI |
| 9753 | * annotations in the array notation). |
| 9754 | */ |
| 9755 | this.register = function(name, constructor) { |
| 9756 | assertNotHasOwnProperty(name, 'controller'); |
| 9757 | if (isObject(name)) { |
| 9758 | extend(controllers, name); |
| 9759 | } else { |
| 9760 | controllers[name] = constructor; |
| 9761 | } |
| 9762 | }; |
| 9763 | |
| 9764 | /** |
| 9765 | * @ngdoc method |
| 9766 | * @name $controllerProvider#allowGlobals |
| 9767 | * @description If called, allows `$controller` to find controller constructors on `window` |
| 9768 | */ |
| 9769 | this.allowGlobals = function() { |
| 9770 | globals = true; |
| 9771 | }; |
| 9772 | |
| 9773 | |
| 9774 | this.$get = ['$injector', '$window', function($injector, $window) { |
| 9775 | |
| 9776 | /** |
| 9777 | * @ngdoc service |
| 9778 | * @name $controller |
| 9779 | * @requires $injector |
| 9780 | * |
| 9781 | * @param {Function|string} constructor If called with a function then it's considered to be the |
| 9782 | * controller constructor function. Otherwise it's considered to be a string which is used |
| 9783 | * to retrieve the controller constructor using the following steps: |
| 9784 | * |
| 9785 | * * check if a controller with given name is registered via `$controllerProvider` |
| 9786 | * * check if evaluating the string on the current scope returns a constructor |
| 9787 | * * if $controllerProvider#allowGlobals, check `window[constructor]` on the global |
| 9788 | * `window` object (not recommended) |
| 9789 | * |
| 9790 | * The string can use the `controller as property` syntax, where the controller instance is published |
| 9791 | * as the specified property on the `scope`; the `scope` must be injected into `locals` param for this |
| 9792 | * to work correctly. |
| 9793 | * |
| 9794 | * @param {Object} locals Injection locals for Controller. |
| 9795 | * @return {Object} Instance of given controller. |
| 9796 | * |
| 9797 | * @description |
| 9798 | * `$controller` service is responsible for instantiating controllers. |
| 9799 | * |
| 9800 | * It's just a simple call to {@link auto.$injector $injector}, but extracted into |
nothing calls this directly
no test coverage detected