当我使用ng serve
一切正常。当我使用ng serve --prod --aot
它时抱怨Type 'any[]' cannot be used as an index type
. 我找不到任何可以修复它的东西。并且它似乎所指的“type any[]”是 tags 变量,因为当我将其注释掉时,一切都会编译。
这是相关的代码:
//cluster-details.component.ts
...
export class ClusterDetailsComponent implements OnInit {
infoTitles = {
edgeNodePublicDNS: 'Edge Node Public DNS',
...
tags: 'Tags'
};
infoKeys: string[];
info: any;
tags: any[];
...
this.requestsService.emrinstanceDetailsGET(body)
.subscribe(
(data) => {
this.infoKeys = Object.keys(data);
this.info = data;
...
集群详细信息.component.html:
<tr *ngFor="let key of infoKeys">
<td>
<strong>{{ infoTitles[key] }}:</strong>
</td>
<td>
{{info[key]}}
</td>
</tr>
<tr>
<td>
<strong>{{ infoTitles[tags] }}:</strong>
</td>
<td>
{{tags}}
</td>
</tr>
请求返回如下数据:
.map(
(response: Response) => {
const data = response.json();
return data['clusterDetail'];
现在我知道'只是不要让它输入'any[]',但我不知道要怎么做。返回的是一个 JSON 值,它只是一个对象类型。将类型更改为 Object 不起作用,我看不到任何其他类型的工作。也许我必须为它制作一个界面?
弄清楚了。一个我不打算使用的变量的简单误用:
HTML 行...{{ infoTitles[tags] }}...
试图用标签变量索引 infoTitles - 我的意思是这是一个只是“标签”的字符串,其中它将正确引用我需要的 infoTitles 值。但我没有发现我正在使用标签数组。所以修复应该只是使用一个字符串或变量,就像tagIndexString = 'tags'
HTML 可以是...{{ infoTitles[tagIndexString] }}...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句