我已经通过以下方式安装了我需要的依赖项:
vis.js:npm install vis --save
@类型/可见:npm install @types/vis --save-dev
代码片段:
import { Component, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
import { Network, DataSet } from 'vis';
@Component({
selector: 'test',
template: '<div #network></div>'
})
export class TestComponent implements AfterViewInit {
@ViewChild('network') el: ElementRef;
private networkInstance: any;
ngAfterViewInit() {
const container = this.el.nativeElement;
const nodes = new DataSet<any>([
{id: 1, label: 'Node 1'},
{id: 2, label: 'Node 2'},
{id: 3, label: 'Node 3'},
{id: 4, label: 'Node 4'},
{id: 5, label: 'Node 5'}
]);
const edges = new DataSet<any>([
{from: 1, to: 3},
{from: 1, to: 2},
{from: 2, to: 4},
{from: 2, to: 5}
]);
const data = { nodes, edges };
this.networkInstance = new Network(container, data);
}
}
我像上面那样尝试只是为了尝试,但它给了我这个错误:
无法读取未定义的属性“解决”
我缺少什么?