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 ?

ohadinho
  • 6,894
  • 16
  • 71
  • 124
  • Might be duplicate please see this answer http://stackoverflow.com/a/41121361/4712391 – Tinus Jackson May 02 '17 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 – ohadinho May 02 '17 at 12:46

2 Answers2

0

You can import your library like this :

import {* as fx} from  '../../../node_modules/money/money.js';
Deblaton Jean-Philippe
  • 11,188
  • 3
  • 49
  • 66
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

sickelap
  • 897
  • 11
  • 21