【发布时间】:2017-05-02 10:42:14
【问题描述】:
我正在对graphing library Vis.JS 进行一些适用性测试。我已经将它与 Angular2 集成,但是我想在单击网络元素时调用 angular2 组件函数。这是我生成基本网络图的组件:
import {Component, OnInit, ViewChild, ElementRef} from '@angular/core'
//reference to visjs library
declare var vis: any;
@Component({
selector: 'visjs',
templateUrl: './app/visJs/visjs.basic.html'
})
export class VisJsBasicComponent implements OnInit {
@ViewChild('network') _element: ElementRef;
ngOnInit() {
this.createBasicNetwork();
}
createBasicNetwork(): void{
// create an array with nodes
var nodes = new vis.DataSet([
{ 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' }
]);
// create an array with edges
var edges = new vis.DataSet([
{ from: 3, to: 1 },
{ from: 1, to: 2 },
{ from: 2, to: 4 },
{ from: 2, to: 5 }
]);
//create the network
var data = {
nodes: nodes,
edges: edges
};
var options = {};
var network = new vis.Network(this._element.nativeElement, data, options);
network.on("click", function (params) {
window.alert('onclick');
});
}
}
而不是
network.on("click", function (params) {
window.alert('onclick');
});
我想做类似的事情
network.on("click", function (params) {
this.myComponentFunction(params);
});
但这是将 angular2 与 jquery 方法混合在一起......我该怎么做?
【问题讨论】: