2

I am a bit confused as to how to add a npm package like ng2-charts to my Angular2 TypeScript project.

By adding :

"ng2-charts": "1.0.3"

to my package.json file, it gets installed nicely, and when I add 'ng2-charts/ng2-charts' to my typescript page:

import {Component, Input, OnInit} from 'angular2/core';
import {Router, RouterLink, RouteParams} from 'angular2/router'
import {CHART_DIRECTIVES} from 'ng2-charts/ng2-charts';

@Component({
    selector: 'detailMatch',
    templateUrl: './app/components/match/detail.html',
    directives: [RouterLink, CHART_DIRECTIVES]
})

It also works perfectly. The name CHART_DIRECTIVE is found automatically in Visual Studio when I type the first letter etc, but when I try to load the page I get:

http://localhost:5000/ng2-charts/ng2-charts.js 404 (Not Found)

This is because I don't have ng2-charts in that location:

It is stored in "lib\js\ng2-charts\ng2-charts.js" Like all my other js files for angular, http, bootstrap, router, Rx etc.

So how can I tell angular that the location of the .js files is in:

 http://localhost:5000/lib/js/ng2-charts/ng2-charts.js
1

1 Answer 1

2

I don't think you are using any module loader. Add the ng2-charts.js file to the script references after angular2 library and see if it works

<script src="/lib/js/ng2-charts/ng2-charts.js"></script>

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

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.