* @ngdoc object * @name ng.$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.
()
| 4747 | * {@link ng.$controllerProvider#register register} method. |
| 4748 | */ |
| 4749 | function $ControllerProvider() { |
| 4750 | var controllers = {}; |
| 4751 | |
| 4752 | |
| 4753 | /** |
| 4754 | * @ngdoc function |
| 4755 | * @name ng.$controllerProvider#register |
| 4756 | * @methodOf ng.$controllerProvider |
| 4757 | * @param {string} name Controller name |
| 4758 | * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI |
| 4759 | * annotations in the array notation). |
| 4760 | */ |
| 4761 | this.register = function(name, constructor) { |
| 4762 | if (isObject(name)) { |
| 4763 | extend(controllers, name) |
| 4764 | } else { |
| 4765 | controllers[name] = constructor; |
| 4766 | } |
| 4767 | }; |
| 4768 | |
| 4769 | |
| 4770 | this.$get = ['$injector', '$window', function($injector, $window) { |
| 4771 | |
| 4772 | /** |
| 4773 | * @ngdoc function |
| 4774 | * @name ng.$controller |
| 4775 | * @requires $injector |
| 4776 | * |
| 4777 | * @param {Function|string} constructor If called with a function then it's considered to be the |
| 4778 | * controller constructor function. Otherwise it's considered to be a string which is used |
| 4779 | * to retrieve the controller constructor using the following steps: |
| 4780 | * |
| 4781 | * * check if a controller with given name is registered via `$controllerProvider` |
| 4782 | * * check if evaluating the string on the current scope returns a constructor |
| 4783 | * * check `window[constructor]` on the global `window` object |
| 4784 | * |
| 4785 | * @param {Object} locals Injection locals for Controller. |
| 4786 | * @return {Object} Instance of given controller. |
| 4787 | * |
| 4788 | * @description |
| 4789 | * `$controller` service is responsible for instantiating controllers. |
| 4790 | * |
| 4791 | * It's just a simple call to {@link AUTO.$injector $injector}, but extracted into |
| 4792 | * a service, so that one can override this service with {@link https://gist.github.com/1649788 |
| 4793 | * BC version}. |
| 4794 | */ |
| 4795 | return function(constructor, locals) { |
| 4796 | if(isString(constructor)) { |
| 4797 | var name = constructor; |
| 4798 | constructor = controllers.hasOwnProperty(name) |
| 4799 | ? controllers[name] |
| 4800 | : getter(locals.$scope, name, true) || getter($window, name, true); |
| 4801 | |
| 4802 | assertArgFn(constructor, name, true); |
| 4803 | } |
| 4804 | |
| 4805 | return $injector.instantiate(constructor, locals); |
| 4806 | }; |
nothing calls this directly
no test coverage detected