* @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.
()
| 9022 | * {@link ng.$controllerProvider#register register} method. |
| 9023 | */ |
| 9024 | function $ControllerProvider() { |
| 9025 | var controllers = {}, |
| 9026 | globals = false; |
| 9027 | |
| 9028 | /** |
| 9029 | * @ngdoc method |
| 9030 | * @name $controllerProvider#register |
| 9031 | * @param {string|Object} name Controller name, or an object map of controllers where the keys are |
| 9032 | * the names and the values are the constructors. |
| 9033 | * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI |
| 9034 | * annotations in the array notation). |
| 9035 | */ |
| 9036 | this.register = function(name, constructor) { |
| 9037 | assertNotHasOwnProperty(name, 'controller'); |
| 9038 | if (isObject(name)) { |
| 9039 | extend(controllers, name); |
| 9040 | } else { |
| 9041 | controllers[name] = constructor; |
| 9042 | } |
| 9043 | }; |
| 9044 | |
| 9045 | /** |
| 9046 | * @ngdoc method |
| 9047 | * @name $controllerProvider#allowGlobals |
| 9048 | * @description If called, allows `$controller` to find controller constructors on `window` |
| 9049 | */ |
| 9050 | this.allowGlobals = function() { |
| 9051 | globals = true; |
| 9052 | }; |
| 9053 | |
| 9054 | |
| 9055 | this.$get = ['$injector', '$window', function($injector, $window) { |
| 9056 | |
| 9057 | /** |
| 9058 | * @ngdoc service |
| 9059 | * @name $controller |
| 9060 | * @requires $injector |
| 9061 | * |
| 9062 | * @param {Function|string} constructor If called with a function then it's considered to be the |
| 9063 | * controller constructor function. Otherwise it's considered to be a string which is used |
| 9064 | * to retrieve the controller constructor using the following steps: |
| 9065 | * |
| 9066 | * * check if a controller with given name is registered via `$controllerProvider` |
| 9067 | * * check if evaluating the string on the current scope returns a constructor |
| 9068 | * * if $controllerProvider#allowGlobals, check `window[constructor]` on the global |
| 9069 | * `window` object (not recommended) |
| 9070 | * |
| 9071 | * The string can use the `controller as property` syntax, where the controller instance is published |
| 9072 | * as the specified property on the `scope`; the `scope` must be injected into `locals` param for this |
| 9073 | * to work correctly. |
| 9074 | * |
| 9075 | * @param {Object} locals Injection locals for Controller. |
| 9076 | * @return {Object} Instance of given controller. |
| 9077 | * |
| 9078 | * @description |
| 9079 | * `$controller` service is responsible for instantiating controllers. |
| 9080 | * |
| 9081 | * It's just a simple call to {@link auto.$injector $injector}, but extracted into |
nothing calls this directly
no test coverage detected