如果答案是可接受的答案,我会try 显示复选标记:
template: `<div ngIf="answer.accepted">✔</div>`
但是我得到了这个错误:
EXCEPTION: No provider for TemplateRef! (NgIf ->TemplateRef)
我做错了什么?
如果答案是可接受的答案,我会try 显示复选标记:
template: `<div ngIf="answer.accepted">✔</div>`
但是我得到了这个错误:
EXCEPTION: No provider for TemplateRef! (NgIf ->TemplateRef)
我做错了什么?
你错过了NgIf前的*
分(就像我们都错过了几十次):
<div *ngIf="answer.accepted">✔</div>
如果没有*
,Angular会看到ngIf
指令正在应用于div
元素,但由于没有*
或<template>
标记,它无法定位模板,因此会出现错误.
如果使用Angular v5时出现此错误:
Error: StaticInjectorError[TemplateRef]:
StaticInjectorError[TemplateRef]:
NullInjectorError: No provider for TemplateRef!
一个或多个组件模板中可能有<template>...</template>
个.将标签更改/更新为<ng-template>...</ng-template>
.