I am attempting to create a recursive function of lines in order to generate a graph, but I am encountering a strange error in the console. It works fine on node.js. Below is the code snippet:
<svg height = "200" width = "300">
<g *ngFor = "let node of nodes; let i = index; let last = last;">
<line
[attr.x1] = nodes[i].x
[attr.y1] = nodes[i].y
[attr.x2] = nodes[i+1].x
[attr.y2] = nodes[i+1].y
/>
<line *ngIf = last
[attr.x1] = nodes[i].x
[attr.y1] = nodes[i].y
[attr.x2] = nodes[i].x
[attr.y2] = nodes[i].y
/>
</g>
</svg>
Below is the TypeScript code:
export class VisitsGraphComponent implements OnInit {
nodes = [
{ x: 0, y: 0 },
{ x: 40, y: 120 },
{ x: 80, y: 80 },
{ x: 120, y: 90 },
{ x: 160, y: 40 }
]
ngOnInit():void {
}
}
I have attempted to simply use the node.x and place it in the ngOnInit(), but encountered the same error:
Cannot read property 'x' of undefined