How to make lodash work with Angular JS?

后端 未结 4 1109
轻奢々
轻奢々 2020-11-28 21:02

I\'m trying to use lodash use it at ng-repeat directives, in this way:

4条回答
  •  盖世英雄少女心
    2020-11-28 21:36

    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._;
      });
    

提交回复
热议问题