Expand Minimize

Enable strict DI mode

Enable strict DI mode to increase Angular's performance in injecting dependencies

CheckId NG1121101
TypeName EnableStrictDiMode
Severity CriticalWarning
Type Application

Enabling the strict DI mode requires you to explicitly annotate injectable functions. Doing so, it improves the performance of Angular injecting dependencies into these functions as it doesn't need to dynamically discover these functions' dependencies.

You can enable the strict DI mode in two ways:

Good practice

<div ng-app="myApp" ng-strict-di>
  
</div>


or

Good practice
angular.bootstrap(document, ['myApp'], {
  strictDi: true
});


Bad practice
    <div ng-app="myApp">
    
    </div>


or

Bad practice
    angular.bootstrap(document, ['myApp']);



Tip: Using a tool like ng-annotate you can automatically annotate all existing functions in your code.

Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.