* @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.
()
| 8885 | * {@link ng.$controllerProvider#register register} method. |
| 8886 | */ |
| 8887 | function $ControllerProvider() { |
| 8888 | var controllers = {}, |
| 8889 | globals = false; |
| 8890 | |
| 8891 | /** |
| 8892 | * @ngdoc method |
| 8893 | * @name $controllerProvider#register |
| 8894 | * @param {string|Object} name Controller name, or an object map of controllers where the keys are |
| 8895 | * the names and the values are the constructors. |
| 8896 | * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI |
| 8897 | * annotations in the array notation). |
| 8898 | */ |
| 8899 | this.register = function(name, constructor) { |
| 8900 | assertNotHasOwnProperty(name, 'controller'); |
| 8901 | if (isObject(name)) { |
| 8902 | extend(controllers, name); |
| 8903 | } else { |
| 8904 | controllers[name] = constructor; |
| 8905 | } |
| 8906 | }; |
| 8907 | |
| 8908 | /** |
| 8909 | * @ngdoc method |
| 8910 | * @name $controllerProvider#allowGlobals |
| 8911 | * @description If called, allows `$controller` to find controller constructors on `window` |
| 8912 | */ |
| 8913 | this.allowGlobals = function() { |
| 8914 | globals = true; |
| 8915 | }; |
| 8916 | |
| 8917 | |
| 8918 | this.$get = ['$injector', '$window', function($injector, $window) { |
| 8919 | |
| 8920 | /** |
| 8921 | * @ngdoc service |
| 8922 | * @name $controller |
| 8923 | * @requires $injector |
| 8924 | * |
| 8925 | * @param {Function|string} constructor If called with a function then it's considered to be the |
| 8926 | * controller constructor function. Otherwise it's considered to be a string which is used |
| 8927 | * to retrieve the controller constructor using the following steps: |
| 8928 | * |
| 8929 | * * check if a controller with given name is registered via `$controllerProvider` |
| 8930 | * * check if evaluating the string on the current scope returns a constructor |
| 8931 | * * if $controllerProvider#allowGlobals, check `window[constructor]` on the global |
| 8932 | * `window` object (not recommended) |
| 8933 | * |
| 8934 | * The string can use the `controller as property` syntax, where the controller instance is published |
| 8935 | * as the specified property on the `scope`; the `scope` must be injected into `locals` param for this |
| 8936 | * to work correctly. |
| 8937 | * |
| 8938 | * @param {Object} locals Injection locals for Controller. |
| 8939 | * @return {Object} Instance of given controller. |
| 8940 | * |
| 8941 | * @description |
| 8942 | * `$controller` service is responsible for instantiating controllers. |
| 8943 | * |
| 8944 | * It's just a simple call to {@link auto.$injector $injector}, but extracted into |
nothing calls this directly
no test coverage detected