* @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.
()
| 8312 | * {@link ng.$controllerProvider#register register} method. |
| 8313 | */ |
| 8314 | function $ControllerProvider() { |
| 8315 | var controllers = {}, |
| 8316 | globals = false, |
| 8317 | CNTRL_REG = /^(\S+)(\s+as\s+(\w+))?$/; |
| 8318 | |
| 8319 | |
| 8320 | /** |
| 8321 | * @ngdoc method |
| 8322 | * @name $controllerProvider#register |
| 8323 | * @param {string|Object} name Controller name, or an object map of controllers where the keys are |
| 8324 | * the names and the values are the constructors. |
| 8325 | * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI |
| 8326 | * annotations in the array notation). |
| 8327 | */ |
| 8328 | this.register = function(name, constructor) { |
| 8329 | assertNotHasOwnProperty(name, 'controller'); |
| 8330 | if (isObject(name)) { |
| 8331 | extend(controllers, name); |
| 8332 | } else { |
| 8333 | controllers[name] = constructor; |
| 8334 | } |
| 8335 | }; |
| 8336 | |
| 8337 | /** |
| 8338 | * @ngdoc method |
| 8339 | * @name $controllerProvider#allowGlobals |
| 8340 | * @description If called, allows `$controller` to find controller constructors on `window` |
| 8341 | */ |
| 8342 | this.allowGlobals = function() { |
| 8343 | globals = true; |
| 8344 | }; |
| 8345 | |
| 8346 | |
| 8347 | this.$get = ['$injector', '$window', function($injector, $window) { |
| 8348 | |
| 8349 | /** |
| 8350 | * @ngdoc service |
| 8351 | * @name $controller |
| 8352 | * @requires $injector |
| 8353 | * |
| 8354 | * @param {Function|string} constructor If called with a function then it's considered to be the |
| 8355 | * controller constructor function. Otherwise it's considered to be a string which is used |
| 8356 | * to retrieve the controller constructor using the following steps: |
| 8357 | * |
| 8358 | * * check if a controller with given name is registered via `$controllerProvider` |
| 8359 | * * check if evaluating the string on the current scope returns a constructor |
| 8360 | * * if $controllerProvider#allowGlobals, check `window[constructor]` on the global |
| 8361 | * `window` object (not recommended) |
| 8362 | * |
| 8363 | * The string can use the `controller as property` syntax, where the controller instance is published |
| 8364 | * as the specified property on the `scope`; the `scope` must be injected into `locals` param for this |
| 8365 | * to work correctly. |
| 8366 | * |
| 8367 | * @param {Object} locals Injection locals for Controller. |
| 8368 | * @return {Object} Instance of given controller. |
| 8369 | * |
| 8370 | * @description |
| 8371 | * `$controller` service is responsible for instantiating controllers. |
nothing calls this directly
no test coverage detected