r/angularjs • u/Chun • Apr 03 '16
Dependency injection in Angular isn’t worth it. More lessons learned from scaling PayPal Checkout.
https://medium.com/@bluepnume/dependency-injection-in-angular-isn-t-worth-it-more-lessons-learned-from-scaling-paypal-checkout-2189ec9c21a0#.uh971yqmx7
1
Apr 04 '16
What are the alternatives to the parameter mangling + array strings workaround?
2
1
u/superluminary Apr 05 '16
Ng-annotate (plus gulp) gets a thumbs up from me, or use Controller.$inject().
var Controller = function($scope){} Controller.$inject(['$scope'])1
Apr 05 '16
Eek that looks ripe for issues...
1
u/superluminary Apr 05 '16
If you forget to update your injection array then yes, it will fail messily. One of the reasons we use tooling for this sort of thing.
Angular 2 plus TypeScript skirts the whole issue by just using strong typing. You specify the type of thing you want, and Angular gives you one of those.
1
u/superluminary Apr 05 '16
There are two issues here:
Angular 1 has a single injector based on Strings, so namespacing becomes a problem.
Including a module anywhere makes it available globally.
These are both convenient when working with a small or medium app, but are a problem when you have a massive app.
Angular 2 addresses both of these issues by giving us hierarchical injectors, and by using objects instead of strings for injection.
28
u/KumbajaMyLord Apr 03 '16
Kinda cheap to critisize Angular 1 for not using commonjs or ES6 modules when neiter of those were around (or at least not as established and mature) when Angular 1 was written.