TS2322:类型 'HTMLDivElement' 不可分配给类型 'TemplateRef<NgIfContext<Skill[]>>'



如果ngIf中的条件不匹配,我正在尝试呈现一个ng模板,但浏览器控制台抛出此错误,并将错误指向"否则":

TS2322: Type 'HTMLDivElement' is not assignable to type 'TemplateRef<NgIfContext<Skill[]>>'.

模板:

<ng-container *ngIf="memberSkills; else noSkills">
<div
*ngFor="let skillLevel of levelsListWithSkills; let i = index"
[attr.data-index]="i"
>
<div
id="{{ skillLevel.skillLevel }}"
[ngClass]="
skillLevel.skillLevel === 'Expert'
? 'badge badge-pill bg-danger'
: skillLevel.skillLevel === 'Intermediate'
? 'badge badge-pill bg-warning'
: skillLevel.skillLevel === 'Beginnner'
? 'badge badge-pill bg-success'
: 'none'
"
>
<span id="title">{{ skillLevel.skillLevel }}</span>
<span *ngFor="let skill of levelsListWithSkills[i].skills">
{{ skill }}
</span>
</div>
</div>
</ng-container>
<div ng-template #noSkills>
<span>Member has not added skills yet.</span>
</div>

尝试

<ng-template #noSkills>
<span>Member has not added skills yet.</span>
</ng-template>

Phrase ng模板不是指令。它是用于呈现HTML元素的Angular模板。它应该以这种方式工作:

<ng-template #noSkills>
<span>Member has not added skills yet.</span>
</ng-template>

相关内容

  • 没有找到相关文章

最新更新