Import Javascript libraries into Angular 2

I had and still have not much experience in web engineering (Javascript, npm-Tool, …) when I started working with Angular 2. There I have a problem that normally one imports an angular-module with e.g. “import {Injectable} from '@angular/core';”. But I want to use the Javascript-library “cytoscape.js”. The problem now is, how to import it such that I can use it.
3 answers

This one is the BEST answer!

I first installed cytoscape.js via npm. In the typescript-file (for Angular) I imported it by “import * as Cytoscape from 'cytoscape';”. And finally to use a Cytoscape instance I could store it in a variable by initializing it via “this.cy = Cytoscape({container: document.getElementById('cy'), … });”.

I have been using Angular 2 for a while, and it can get quite confusing.
I strongly recomend using Angular CLI, not only becuase it creates a basic working application (with a properly organized skeleton), but because it helps the administration of libraries (angular internal or external).
In order to install a library, if you're using Angular CLI, your project (in Angular 2) will have a package "angular-cli.json" where under the section "scripts" every installed package (.js) is referenced.
You will only need to launch the command ng serve, and all packages referenced will be installed!!

I have been using Angular 2 for a while, and it can get quite confusing.
I strongly recomend using Angular CLI, not only becuase it creates a basic working application (with a properly organized skeleton), but because it helps the administration of libraries (angular internal or external).
In order to install a library, if you're using Angular CLI, your project (in Angular 2) will have a package "angular-cli.json" where under the section "scripts" every installed package (.js) is referenced.
You will only need to launch the command ng serve, and all packages referenced will be installed!!