How do i use lodash with Ionic 2? How do i use lodash with Ionic 2? typescript typescript

How do i use lodash with Ionic 2?


  1. Install lodash with npm from your terminal:

    $:npm i -S lodash // npm install --save lodash (--save,-S saves to package.json)
  2. Import lodash in your component like this:

    import * as _ from 'lodash';


Starting from Ionic 2 RC0 you have to do the following.

npm install @types/lodash --save-dev --save-exact

and import it like

import _ from 'lodash';


For Future Users of Ionic 3

npm install lodash --savenpm install @types/lodash --save

Official Doc

npm install will download a copy of the library from NPM and save it in your app’s node_modules directory. --save will tell the NPM CLI to add an entry to your app’s package.json dependency list. You can use the library now.

If you want to import all functions from lodash then use

import lodash from 'lodash';lodash.capitalize('myStringToCapitalize');

If you want to use specific function from lodash then use

import { shuffle } from 'lodash';shuffle(results);