aboutsummaryrefslogtreecommitdiffstats
path: root/src/service/controller.js
blob: 229ce14aa480741719df4aa82202f9d143afafea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';

function $ControllerProvider() {
  this.$get = ['$injector', '$window', function($injector, $window) {

    /**
     * @ngdoc function
     * @name angular.module.ng.$controller
     * @requires $injector
     *
     * @param {Function|string} Class Constructor function of a controller to instantiate, or
     *        expression to read from current scope or window.
     * @param {Object} locals Injection locals for Controller.
     * @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, locals) {
      if(isString(Class)) {
        var expression = Class;
        Class = getter(locals.$scope, expression, true) || getter($window, expression, true);
        assertArgFn(Class, expression);
      }

      return $injector.instantiate(Class, locals);
    };
  }];
}