* @ngdoc provider * @name $controllerProvider * @this * * @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.
()
| 10936 | * {@link ng.$controllerProvider#register register} method. |
| 10937 | */ |
| 10938 | function $ControllerProvider() { |
| 10939 | var controllers = {}, |
| 10940 | globals = false; |
| 10941 | |
| 10942 | /** |
| 10943 | * @ngdoc method |
| 10944 | * @name $controllerProvider#has |
| 10945 | * @param {string} name Controller name to check. |
| 10946 | */ |
| 10947 | this.has = function(name) { |
| 10948 | return controllers.hasOwnProperty(name); |
| 10949 | }; |
| 10950 | |
| 10951 | /** |
| 10952 | * @ngdoc method |
| 10953 | * @name $controllerProvider#register |
| 10954 | * @param {string|Object} name Controller name, or an object map of controllers where the keys are |
| 10955 | * the names and the values are the constructors. |
| 10956 | * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI |
| 10957 | * annotations in the array notation). |
| 10958 | */ |
| 10959 | this.register = function(name, constructor) { |
| 10960 | assertNotHasOwnProperty(name, 'controller'); |
| 10961 | if (isObject(name)) { |
| 10962 | extend(controllers, name); |
| 10963 | } else { |
| 10964 | controllers[name] = constructor; |
| 10965 | } |
| 10966 | }; |
| 10967 | |
| 10968 | /** |
| 10969 | * @ngdoc method |
| 10970 | * @name $controllerProvider#allowGlobals |
| 10971 | * @description If called, allows `$controller` to find controller constructors on `window` |
| 10972 | * |
| 10973 | * @deprecated |
| 10974 | * sinceVersion="v1.3.0" |
| 10975 | * removeVersion="v1.7.0" |
| 10976 | * This method of finding controllers has been deprecated. |
| 10977 | */ |
| 10978 | this.allowGlobals = function() { |
| 10979 | globals = true; |
| 10980 | }; |
| 10981 | |
| 10982 | |
| 10983 | this.$get = ['$injector', '$window', function($injector, $window) { |
| 10984 | |
| 10985 | /** |
| 10986 | * @ngdoc service |
| 10987 | * @name $controller |
| 10988 | * @requires $injector |
| 10989 | * |
| 10990 | * @param {Function|string} constructor If called with a function then it's considered to be the |
| 10991 | * controller constructor function. Otherwise it's considered to be a string which is used |
| 10992 | * to retrieve the controller constructor using the following steps: |
| 10993 | * |
| 10994 | * * check if a controller with given name is registered via `$controllerProvider` |
| 10995 | * * check if evaluating the string on the current scope returns a constructor |
nothing calls this directly
no test coverage detected