我经常在我的应用程序中使用ng-templates,以后再将它们包括在* ngTemplateOutlet中,并将其传递给上下文。但是,当我定义模板本身时,它不知道上下文将具有的接口,所以说:
<ng-template #willUseLater
let-item
let-index="index">
{{index}} — {{item}}
</ng-template>
给我类似ng: The template context does not defined a member called 'index'
的错误。
有什么方法可以告诉ng-template以后使用它时将具有什么上下文?
当在Angular中将ng-template与Kendo Grid一起使用时,我遇到相同的问题。我拥有的html是有效的,并且在启动时可以正确编译和运行,但随后Visual Studio Code检测到相同的错误。
<kendo-grid-column field="countryID"
title="{{ 'location.country' | translate }}"
width="10">
<ng-template kendoGridEditTemplate
let-dataItem="dataItem"
let-column="column"
let-formGroup="formGroup">
<app-dropdown-single
[placeholder]="column.title"
[formControl]="formGroup?.controls['countryID']"
[data]="dataDdwCountry"
valueField="id">
</app-dropdown-single>
</ng-template>
</kendo-grid-column>
因此,基本上,Visual Studio Code为我提供了ng-template的3个参数的错误。但是,在编译时,占位符确实显示了“ column”的正确值。如果我仅将其保留为let-column而不是let-column =“ column”,则错误消失,但是我需要的值也消失了(列现在未定义,我需要该值)。
有人可以帮忙吗?