How to include 3rd party library that uses older import approach to Angular4.x?

Viewed 2306

What is the proper workflow to include the library to angular 4.0 and use it inside a component?

My steps:

yarn add mathjs

Then there should be a way to injects js libraries in one of the build lifecycles so the angular4 component can use it. JHipster utilizes Webpack and Yarn.

Then I tried to add to Component (docs):

import { mathjs } from "./mathjs";  

and

var math = require('mathjs');

Those were not working. What am I missing?

UPDATE:

It seems like mathjs uses older approach suggesting var math = require('mathjs'). Maybe it is similar to JQuery question in some way...

UPDATE2

3 Answers

I did this way and it worked for angular9.

First install npm package mathjs.

npm install mathjs

Then import in your component or directive.

import { round } from 'mathjs'

You may test with this.

console.log(round(math.pi, 3) )
Related