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?
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.
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.
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.
Install lodash
with npm
from your terminal:
$:npm i -S lodash
// npm install --save lodash (--save,-S saves to package.json)
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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With