Saturday, June 9, 2018

Adding third party library in ionic 2 | ionic 3 | ionic 4

Installation Using NPM


To add a third party library to an app, run the following command:

 npm install <theLibraryName> –save

 For example, to install the library :

npm install faye –save

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


How to use  Libraries


 After installing the library, we must import it into our TS file to use it.

 Import statements can follow two simple patterns: using a named export and using a default export. The best practice is to use the named export pattern whenever possible. If it doesn’t work correctly, fall back to the default export.

// named export pattern

import { myFunction } from ‘theLibraryName’;

Eg :

import  { myFaye }  from ‘faye’;

– OR –

 // default export pattern

import myLibrary from ‘theLibraryName’;

Eg :

import  myFaye  from ‘faye’;

No comments:

Post a Comment