0

I'm trying to import js library money.js (https://www.npmjs.com/package/money) into an angular 4 component.

I've installed it by npm install money and added the following code to my component:

declare var fx: any;

import '../../../node_modules/money/money.js';

Within the component i've tried to use it:

fx.convert(12.99, {from: "GBP", to: "HKD"});

Unfortunately, i'm getting an error that fx is not defined.

It's important to mention that money.js file DID get loaded (I find it when searching the sources in developer tools).

Can someone assist ?

2
  • Might be duplicate please see this answer stackoverflow.com/a/41121361/4712391 Commented May 2, 2017 at 12:42
  • i've tried this way either.. doesn't work. as I mentioned: js file DID gets loaded. For some reason I cannot use the function fx within money.js Commented May 2, 2017 at 12:46

2 Answers 2

0

If you want to access imported variable you should give it a name.

import * as fx from 'money';

should be enough. We're using lodash in our codebase like that.

Hope that helps

Sign up to request clarification or add additional context in comments.

Comments

0

You can import your library like this :

import {* as fx} from  '../../../node_modules/money/money.js';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.