How to make lodash work with Angular JS?

I prefer to introduce ‘_’ globally and injectable for tests, see my answer to this question
Use underscore inside controllers

var myapp = angular.module('myApp', [])
  // allow DI for use in controllers, unit tests
  .constant('_', window._)
  // use in views, ng-repeat="x in _.range(3)"
  .run(function ($rootScope) {
     $rootScope._ = window._;
  });

Leave a Comment