Angular 4 and Lodash

Lodash is a pretty cool utility library for doing stuff in javascript objects.  The maintainers have done a lot of work to make it as efficient as possible, (about 4kB gzipped and minified), so it won’t eat up a bunch of resources on your web application.

One of the reasons I always seem to bring in Lodash to my applications is their array/collection functions.  Filtering, getting subsets, etc, are all included and makes me (a .NET guy) feel at home in javascript.

Including it in an Angular 4 application wasn’t exactly straightforward, so I thought I would document it here:

First, install lodash via NPM:

npm install –save lodash

Then, install the @types/lodash package.  This is what Typescript uses

npm install –save @types/lodash

Then, in whatever file you want to use it:

import * as _ from “lodash”;

And that’s it!

Leave a Reply

Your email address will not be published. Required fields are marked *