Hi all,
I’ve recently filed an issue <https://github.com/angular/angular.js/issues/10951>, and I was hoping to get some feedback on a proposed resolution. I’d like to break up the $ControllerProvider so that the constructor resolution can be overridden easily, as it seems to have been intended. My first thought would be to create a new $ControllerResolver service, which the current $ControllerProvider would inject. This $ControllerResolver would only be responsible for resolving and returning the controller constructor. So it would extract this logic: expression = controllers.hasOwnProperty(constructor) ? controllers[constructor] : getter(locals.$scope, constructor, true) || (globals ? getter($window, constructor, true) : undefined); from $ControllerProvider. Something like this perhaps: function $ControllerResolver() { var controllers = {}, globals = false; this.register = function(name, constructor) { assertNotHasOwnProperty(name, 'controller'); if (isObject(name)) { extend(controllers, name); } else { controllers[name] = constructor; } }; this.allowGlobals = function() { globals = true; }; this.$get = ['$injector', '$window', function($injector, $window) { return function(constructor, locals){ if (controllers.hasOwnProperty(constructor)) return controllers[constructor]; else if ($injector.has(constructor)) return $injector.get(constructor); else return getter(locals.$scope, constructor, true) || (globals ? getter($window, constructor, true) : undefined); } }] } If anyone has other ideas, I’m open to them. Right now I’m just looking to get started on a pull request that has a good chance of being merged. Thanks, Scott -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
