저는 Angular 4 app에서 d3.js
으로 작업하고 있습니다. 함수를 호출하려고하는데 오류가 ERROR TypeError: this.highlightNodes is not a function
이됩니다.this.someFunction (params)는 각도 4의 함수가 아닙니다.
여기에 내가 작업 한 코드입니다 :
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");
}
}
는 로컬 바인딩 때문에 bind(this)
가 도움이되지 않은 사용. 함수를 적절한 방법으로 호출하는 방법으로이를 해결하도록 도와주십시오.
. 컨텍스트가 변경됩니다. 'nClickNode를보십시오 : (url, opts) => {}' – Rajesh
'this' (말장난 의도)에 속아 있어야합니다 :) – abhishekkannojia