gpt4 book ai didi

angular - 没有 TemplateRef 的提供者! (NgIf ->TemplateRef)

转载 作者:太空狗 更新时间:2023-10-29 16:44:13 27 4
gpt4 key购买 nike

如果答案是已接受的答案,我会尝试显示复选标记:

template: `<div ngIf="answer.accepted">&#10004;</div>`

但是我得到这个错误:

EXCEPTION: No provider for TemplateRef! (NgIf ->TemplateRef)

我做错了什么?

最佳答案

您错过了 *在 NgIf 面前(就像我们都经历过几十次一样):

<div *ngIf="answer.accepted">&#10004;</div>

没有 * , Angular 看到 ngIf指令正在应用于 div元素,但由于没有 *<template>标记,它无法找到模板,因此会出现错误。


如果您在使用 Angular v5 时遇到此错误:

Error: StaticInjectorError[TemplateRef]:
  StaticInjectorError[TemplateRef]:
    NullInjectorError: No provider for TemplateRef!

你可能有<template>...</template>在一个或多个组件模板中。将标签更改/更新为 <ng-template>...</ng-template> .

关于angular - 没有 TemplateRef 的提供者! (NgIf ->TemplateRef),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35932074/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com