Using mgechev's angular2-seed, I'm trying to get to grips with Angular2 and Typescript for a new project, but have run into this problem.
I want to use Numeral in a component, so I:
npm install numeral
typings install dt~numeraljs --global --save
import { numeral } from '/typings/globals/numeraljs';
let num:Number = new Number(numeral().unformat(text));
So far, so good. Everything seems to transpile ok. Until I get to the browser, where I get in the console:
Error: XHR error (404 Not Found) loading http://localhost:5555/typings/globals/numeraljs.js(…)
What am I doing wrong here? Have I missed a step out to tell Typescript where the actual code is?
Typically what you want to do is, if the package is not a native Typescript module:
import * as numeral from 'numeral';
The typings folder is just for telling Typescript what the type definitions are, so it will use it for code highlighting and linting. The actual module you want to import sits in the node_modules
folder and can be imported with its name.
If it's still complaining about not finding the numeral
module you could add
/// <reference path="typings/globals/numeraljs/numeraljs.d.ts"/>
or wherever the Typescript definition file is stored.
you need also to add a reference link to actual numeraljs.js file. in your index.html page
say that you have index.html page as your main page, add the numeraljs.js to head
<head>
<script src="myScriptLib/numeral/numeraljs.js"></script>
</head>
also you can use system.js to load all needed scripts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With