Use underscore inside Angular controllers

前端 未结 6 1143
轮回少年
轮回少年 2020-11-30 16:16

How do I use underscore library inside angularjs controllers?

On this post: AngularJS limitTo by last 2 records somebody suggested to assign an _ variable to the ro

6条回答
  •  一整个雨季
    2020-11-30 16:45

    I use this:

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

    See https://github.com/angular/angular.js/wiki/Understanding-Dependency-Injection about halfway for some more info on run.

提交回复
热议问题