Roadmap › AngularJS (1.x) — Legacy › Module: Services and Dependency Injection
Lessons in this course (13)
7. Dependency injection and minification
Intermediate★ Must knowLesson 7 of 13
AngularJS reads function parameter names to know what to inject. Minifiers rename parameters, which breaks DI — use an annotation style:
js
// Inline array annotation (most common)
app.controller("OrderController", ["$scope", "orderApi", function ($scope, orderApi) { /* ... */ }]);
// $inject property
function OrderController(orderApi) { /* ... */ }
OrderController.$inject = ["orderApi"];
// Build-time: ng-annotate / babel-plugin-angularjs-annotate; strict mode: <html ng-app="app" ng-strict-di>