Use underscore inside Angular controllers

前端 未结 6 1148
轮回少年
轮回少年 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 17:06

    I have implemented @satchmorun's suggestion here: https://github.com/andresesfm/angular-underscore-module

    To use it:

    1. Make sure you have included underscore.js in your project

      
      
    2. Add the module as a dependency in your App definition

      var myapp = angular.module('MyApp', ['underscore'])
      
    3. To use, add as an injected dependency to your Controller/Service and it is ready to use

      angular.module('MyApp').controller('MyCtrl', function ($scope, _) {
      ...
      //Use underscore
      _.each(...);
      ...
      

提交回复
热议问题