Sanity checking with ng-strict-di

The ng-strict-di directive is new and extremely simple to understand. When declaring the parent DOM node for your application, if ng-strict-di is included in that element, functions without the minification-safe dependency injection syntax will fail to execute.

How to do it…

Using the ng-strict-di directive is as simple as adding an extra attribute to your ng-app node, as follows:

(app.js)

angular.module('myApp',[])
.controller('Ctrl', function($scope) {});

(index.html)

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

If you try to load the page in your browser, you will be greeted with the following error:

Error: [$injector:strictdi] function($provide) is not using explicit annotation and ...

Get AngularJS Web Application Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.