Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Controller decorators broken in 1.3 #9839

Closed
gampleman opened this issue Oct 30, 2014 · 2 comments
Closed

Controller decorators broken in 1.3 #9839

gampleman opened this issue Oct 30, 2014 · 2 comments

Comments

@gampleman
Copy link
Contributor

This code used to work in Angular 1.2.x, which we use to resolve some dependencies for our controllers that need to be resolved dynamically.

angular.module('TestApp', []).config(function($provide) {
    $provide.decorator('$controller', function($delegate) {
        return function(expression, locals) {
            locals = _.extend(locals, MY_CUSTOM_LOCALS);
          }
          return $delegate(expression, locals);
        };
      }
    );
  })

This can be fixed by passing in the private later, ident parameters, but since these are undocumented, this valid use case breaks without no notice. Also the error is extremely unhelpful:

TypeError: object is not a function
    at http://localhost:9000/95bcabadceecdd8826e2615bcb4572c1c2d52628/app/vendor/bower_components/angular/angular.js:7594:13
    at forEach (http://localhost:9000/95bcabadceecdd8826e2615bcb4572c1c2d52628/app/vendor/bower_components/angular/angular.js:343:20)
    at nodeLinkFn (http://localhost:9000/95bcabadceecdd8826e2615bcb4572c1c2d52628/app/vendor/bower_components/angular/angular.js:7593:11)
    at compositeLinkFn (http://localhost:9000/95bcabadceecdd8826e2615bcb4572c1c2d52628/app/vendor/bower_components/angular/angular.js:6991:13)
    at publicLinkFn (http://localhost:9000/95bcabadceecdd8826e2615bcb4572c1c2d52628/app/vendor/bower_components/angular/angular.js:6870:30)
    at http://localhost:9000/95bcabadceecdd8826e2615bcb4572c1c2d52628/app/vendor/bower_components/angular-ui-router/release/angular-ui-router.js:3336:9
    at invokeLinkFn (http://localhost:9000/95bcabadceecdd8826e2615bcb4572c1c2d52628/app/vendor/bower_components/angular/angular.js:8111:9)
    at nodeLinkFn (http://localhost:9000/95bcabadceecdd8826e2615bcb4572c1c2d52628/app/vendor/bower_components/angular/angular.js:7623:11)
    at compositeLinkFn (http://localhost:9000/95bcabadceecdd8826e2615bcb4572c1c2d52628/app/vendor/bower_components/angular/angular.js:6991:13)
    at publicLinkFn 
@lgalfaso
Copy link
Contributor

monkey patching any of the existing angular services is not something that was ever supported (and maybe this will never be the case). Now, the right way to delegate a call is return $delegate.apply($delegate, arguments);

@gampleman
Copy link
Contributor Author

What's the point of the decorator then?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants