Angular 没有TemplateRef的提供程序!(NgIf->;TemplateRef)

Angular 没有TemplateRef的提供程序!(NgIf->;TemplateRef),angular,angular2-template,Angular,Angular2 Template,如果答案是可接受的答案,我尝试显示复选标记: template: `<div ngIf="answer.accepted">&#10004;</div>` 我做错了什么?你错过了NgIf面前的*(就像我们都错过了几十次): ✔; 如果没有*,Angular会看到ngIf指令正在应用于div元素,但由于没有*或标记,因此无法定位模板,因此出现错误 如果使用Angular v5时出现此错误: 错误:StaticInjectorError[Templ

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

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

我做错了什么?

你错过了NgIf面前的
*
(就像我们都错过了几十次):

✔;

如果没有
*
,Angular会看到
ngIf
指令正在应用于
div
元素,但由于没有
*
标记,因此无法定位模板,因此出现错误


如果使用Angular v5时出现此错误:

错误:StaticInjectorError[TemplateRef]:
StaticInjectorError[TemplateRef]:
NullInjectorError:没有TemplateRef的提供程序


在一个或多个组件模板中可能有
。将标签更改/更新为

,这样,我可以帮助您了解您犯了什么(以及在哪里)错误,但在此之前,我们需要阅读文档:

通过在 元素(或前缀为*)的指令)。TemplateRef 因为嵌入式视图被注入到 指令,使用TemplateRef标记

您还可以使用查询来查找与 组件或指令

因此:

  • 使用
    [ngIf]=“something”
    时,必须使用
    访问模板引用(例如:使用
    时)
  • 使用
    *ngIf
    您可以在您想要的地方使用它,因为*保证访问模板引用(例如:使用
    时)

如果您在代码中使用类似于
{{message}}
的内容,您可能会遇到一些错误。

如果您使用不带星号的ngSwitchCase,同样的情况也会发生!好极了你解决了我的问题。必须以某种方式替换
EXCEPTION: No provider for TemplateRef! (NgIf ->TemplateRef)
<div *ngIf="answer.accepted">&#10004;</div>