'Get Array of Values from a Nested Data
guys. How to get values from an array of the nested object, which I getting from the parent component.
For example:
@Input() result?: FullResult;
constructor() {}
ngOnInit(): void {
Chart.register(...registerables);
chart.default.createChart()
}
updateData() {
const data = this.result?.threePhaseResult.chartSet;
console.log(data). // Here I get the object, that consist two objects - Curve and EnvelopeCurve. Both objects include an array of coordinate.
const time = data?.Curve.map(function(coordinate) { return coordinate.X});
const K = data?.Curve.map(function(coordinate) { return coordinate.Y});
const Kenv = data?.EnvelopeCurve.map(function(coordinate) { return coordinate.Y});
this.chart.config.labels = time;
this.chart.config.data.datasets[0].data = K;
this.chart.config.data.datasets[0].data = Kenv;
this.chart.update()
}
I always get "TypeError: undefined is not an object (evaluating 'a.data.Curve.map')". Please help me to fix my mistake.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|