I am working with d3.js
in an Angular 4 app. I am trying to call a function, but it throws me an error as ERROR TypeError: this.highlightNodes is not a function
.
Here's the code, I was working on:
import {Component, OnInit} from '@angular/core';
declare let d3:any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
ngOnInit() {
this.networkGraph();
}
networkGraph() {
d3.netJsonGraph("../assets/json/network.json",
{
el: "#randomDiv",
onClickNode: function (url, opts) {
//Here's the error being thrown
this.highlightNodes(url, "nodes", true);
}
}
);
}
highlightNodes(url, type, initial) {
console.log("Its working");
}
}
Using bind(this)
is not helping because it is binding locally. Please help me resolve this as how to call the function the proper way.