首页 文章

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

提问于
浏览
166

如果答案是接受的答案,我试图显示一个复选标记:

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

但我得到这个错误:

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

我究竟做错了什么?

3 回答

  • 1

    当我做 [ngSwitchCase]="" 而不是实际的 *ngSwitchCase="" ,或者我实际上打算做的事情,这是 [ngSwitch]="" .

  • 1

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

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

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


    如果Angular v5出现此错误:

    错误:StaticInjectorError [TemplateRef]:StaticInjectorError [TemplateRef]:NullInjectorError:没有TemplateRef的提供者!

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

  • 370

    我没有收到包含模板或类似问题的错误 . 发生此错误是因为某些代码错误,如:

    `objects.someProperty1> 0其中'someProperty1'属性可能不存在 .

    所以其他一些错误的代码可能会触发此错误 . 希望能帮助到你!

相关问题