Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2, how to import visjs

I just add visjs to my node modules so now I would like to import visjs like that:

import * as Vis from 'vis';
import { Component, ViewChild, ElementRef } from '@angular/core';

@Component({
  selector: 'center-pane',
  templateUrl: './center-pane.component.html',
  styleUrls: ['./center-pane.component.scss']
})
export class CenterPaneComponent {

  constructor(){}

  ngAfterViewInit(){
     console.log(Vis);
  }
}

But it doesn't work, 'vis' is not found.

How can I do ?

To bypass that I currently use the lib like that :

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.1/vis.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.1/vis.min.css" rel="stylesheet" type="text/css" />

But it's not the best way to use it...

like image 326
Charly berthet Avatar asked Feb 02 '17 16:02

Charly berthet


1 Answers

Besides installing vis, you also need to install its type definitions.

npm install vis --save
npm install @types/vis --save-dev

After that, you can import and use vis elements:

import { Network, DataSet, Node, Edge, IdType } from 'vis';
like image 56
amccampos Avatar answered Oct 01 '22 13:10

amccampos