【发布时间】:2018-06-09 15:33:51
【问题描述】:
我正在创建这样的组件,但在 ng serve/building 时出现错误。 不要像一些评论者认为的那样与控制台上的错误混淆。 预期行为适用于构建和运行的代码。
TS error TS2349: Cannot invoke an expression whose type lacks a call signature
在ngOnInit()的foreach函数中
import { Component, OnInit, Input } from '@angular/core';
import { ChartInput, MultiChartInput, ChartColorScheme } from "@shared/models/chart-input";
@Component({
selector: 'chart-legend',
templateUrl: './chart-legend.component.html',
styleUrls: ['./chart-legend.component.css']
})
export class ChartLegendComponent implements OnInit {
@Input()
public chartInput: ChartInput[] | MultiChartInput[];
@Input()
public legendColors: ChartColorScheme;
public legends: Map<string, string> = new Map<string, string>();
constructor() { }
ngOnInit() {
this.chartInput.forEach(
(item, index) => {
this.legends.set(item.name, this.legendColors.domain[index]);
});
}
}
export class ChartInput {
name: string;
value: number;
}
export class MultiChartInput {
name: string;
series: ChartInput[];
}
export class ChartColorScheme {
domain: string[];
}
感谢任何解决问题的帮助。 如果有人认为这与此question 有关。请解释。我不这么认为。
【问题讨论】:
-
检查 ngOnInit() 中的 console.log(this.chartInput);
-
@orangespark nope.. 我会通过的。请比较它并标记重复。错误是一样的。但不同的用例。
-
@Ajay ...我想为此构建..你认为.??
-
您在代码中使用的这个 sn-p 是否准确?
标签: javascript arrays angular typescript