diff options
Diffstat (limited to 'src/service')
| -rw-r--r-- | src/service/controller.js | 26 | ||||
| -rw-r--r-- | src/service/formFactory.js | 6 | ||||
| -rw-r--r-- | src/service/route.js | 6 |
3 files changed, 32 insertions, 6 deletions
diff --git a/src/service/controller.js b/src/service/controller.js new file mode 100644 index 00000000..22fb3b02 --- /dev/null +++ b/src/service/controller.js @@ -0,0 +1,26 @@ +'use strict'; + +function $ControllerProvider() { + this.$get = ['$injector', function($injector) { + + /** + * @ngdoc function + * @name angular.module.ng.$controller + * @requires $injector + * + * @param {Function} Class Constructor function of a controller to instantiate. + * @param {Object} scope Related scope. + * @return {Object} Instance of given controller. + * + * @description + * `$controller` service is responsible for instantiating controllers. + * + * It's just simple call to {@link angular.module.AUTO.$injector $injector}, but extracted into + * a service, so that one can override this service with {@link https://gist.github.com/1649788 + * BC version}. + */ + return function(Class, scope) { + return $injector.instantiate(Class, {$scope: scope}); + }; + }]; +} diff --git a/src/service/formFactory.js b/src/service/formFactory.js index 5d64131e..69c6d717 100644 --- a/src/service/formFactory.js +++ b/src/service/formFactory.js @@ -102,8 +102,8 @@ function $FormFactoryProvider() { var $parse; - this.$get = ['$rootScope', '$parse', '$injector', - function($rootScope, $parse_, $injector) { + this.$get = ['$rootScope', '$parse', '$controller', + function($rootScope, $parse_, $controller) { $parse = $parse_; /** * @ngdoc proprety @@ -136,7 +136,7 @@ function $FormFactoryProvider() { function formFactory(parent) { var scope = (parent || formFactory.rootForm).$new(); - $injector.instantiate(FormController, {$scope: scope}); + $controller(FormController, scope); return scope; } diff --git a/src/service/route.js b/src/service/route.js index 04bcfdb6..f8200fd4 100644 --- a/src/service/route.js +++ b/src/service/route.js @@ -63,8 +63,8 @@ </doc:example> */ function $RouteProvider(){ - this.$get = ['$rootScope', '$location', '$routeParams', '$injector', - function( $rootScope, $location, $routeParams, $injector) { + this.$get = ['$rootScope', '$location', '$routeParams', '$controller', + function( $rootScope, $location, $routeParams, $controller) { /** * @ngdoc event * @name angular.module.ng.$route#$beforeRouteChange @@ -280,7 +280,7 @@ function $RouteProvider(){ copy(next.params, $routeParams); next.scope = parentScope.$new(); if (next.controller) { - $injector.instantiate(next.controller, {$scope: next.scope}); + $controller(next.controller, next.scope); } } } |
