Use Underscore In Your AngularJS Controllers

Posted By Weston Ganger

I wanted to be able to use underscore in my controllers.

Make sure you include underscore.js on the page

First we will create a service or factory so we can inject it

// Declare it as a dependency of your module
var app = angular.module('app', ['underscore']);

// And then inject it on the controllers where you need it
app.controller('ListCtrl', function($scope, _) {
  // do stuff with underscore
});

Related External Links:

Article Topic:Software Development - Javascript

Date:July 21, 2015