如果答案是接受的答案,我试图显示一个复选标记:
template: `<div ngIf="answer.accepted">✔</div>`
但我得到这个错误:
EXCEPTION: No provider for TemplateRef! (NgIf ->TemplateRef)
我究竟做错了什么?
当我做 [ngSwitchCase]="" 而不是实际的 *ngSwitchCase="" ,或者我实际上打算做的事情,这是 [ngSwitch]="" .
[ngSwitchCase]=""
*ngSwitchCase=""
[ngSwitch]=""
你错过了NgIf面前的 * (就像我们都有,几十次):
*
<div *ngIf="answer.accepted">✔</div>
如果没有 * ,Angular会看到 ngIf 指令正在应用于 div 元素,但由于没有 * 或 <template> 标记,因此无法找到模板,因此错误 .
ngIf
div
<template>
如果Angular v5出现此错误:
错误:StaticInjectorError [TemplateRef]:StaticInjectorError [TemplateRef]:NullInjectorError:没有TemplateRef的提供者!
您可能在一个或多个组件模板中有 <template>...</template> . 将标签更改/更新为 <ng-template>...</ng-template> .
<template>...</template>
<ng-template>...</ng-template>
我没有收到包含模板或类似问题的错误 . 发生此错误是因为某些代码错误,如:
`objects.someProperty1> 0其中'someProperty1'属性可能不存在 .
所以其他一些错误的代码可能会触发此错误 . 希望能帮助到你!
3 回答
当我做
[ngSwitchCase]=""
而不是实际的*ngSwitchCase=""
,或者我实际上打算做的事情,这是[ngSwitch]=""
.你错过了NgIf面前的
*
(就像我们都有,几十次):如果没有
*
,Angular会看到ngIf
指令正在应用于div
元素,但由于没有*
或<template>
标记,因此无法找到模板,因此错误 .如果Angular v5出现此错误:
您可能在一个或多个组件模板中有
<template>...</template>
. 将标签更改/更新为<ng-template>...</ng-template>
.我没有收到包含模板或类似问题的错误 . 发生此错误是因为某些代码错误,如:
所以其他一些错误的代码可能会触发此错误 . 希望能帮助到你!