简体   繁体   中英

How to use installed modules in aurelia

I am using the skeleton-typescript sample and work through the documentation. I am trying to set up a value converter with numeral as it is shown in the docs .

import numeral from 'numeral';

export class CurrencyFormatValueConverter {
  toView(value) {
    return numeral(value).format('($0,0.00)');
  }
}

I have installed numeral via jspm install numeral . It is added package.json within the jspm dependencies and I manually added it to bundles.js.

After saving the typescript file I get the error: Cannot find module 'numeral'. . What am I missing?

You need d.ts for numeral.js. and since there is no d.ts on Typings this can resolve problem:

$ jspm install npm:@types/numeral.

It works in my skeleton with value converters. Import can be done like import * as numeral from 'numeral' ;

You should add it in your configuration like:

export function configure(aurelia) {
    aurelia.use
        .standardConfiguration()
        .developmentLogging()
        .plugin('numeral'); 

    aurelia.start().then(() => aurelia.setRoot());
}

You will find the exact package names in your package.json:

jspm": {
   "dependencies": {
        ...
        "numeral": "xxxx"
        ...
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM