Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i use lodash with Ionic 2?

I've just started working on a new project, using Ionic 2. I'm new to TypeScript, and have been trying to figure out how to include lodash to my project.

Is there anyone out there who has done this, and can point me in the right direction?

like image 575
larschla Avatar asked Oct 29 '15 05:10

larschla


People also ask

How use NPM package in ionic?

Installation Using NPMnpm 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. The library is now ready to use.

Can I use Lodash in angular?

Adding Lodash To Angular The first thing you want to do is add the Lodash package to your project using NPM/Yarn. This adds Lodash to our project and at this point is ready for use, but it's just the raw library. What we also need is the type definitions to give us some nice strongly typed defintions inside Typescript.

Can we use Lodash in TypeScript?

Consuming. From there you'll be able to use lodash in your TypeScript code with no fuss. This works for both modules and global code.


2 Answers

  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';
    
like image 104
Daniel Wei Avatar answered Sep 19 '22 07:09

Daniel Wei


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';
like image 20
Shamsher Avatar answered Sep 19 '22 07:09

Shamsher