There are two ways to use the “this” keyword in TypeScript or an Angular project.
First : If you use a function name without the “function” keyword, like in an arrow function in JavaScript, “this” represents the global scope, not the local scope.
Example :
export class ClassName {
private svg : any
constructor() {}
private abc() : void {
this.svg.attr("fill", (d)=> {
// there ()=>{} (Arrow Function) represents the global 'this' keyword
return d;
})
}
}
Second : If you use the “function” keyword in steed of arrow function, then “this” is treated as the local scope.
Example :
export class ClassName {
private svg : any