ERROR 错误:ngIfElse 必须是 TemplateRef,但收到“true”
HTML 文件
<select class="form-control">
<option selected value="0">Select Manufacturer</option>
<option *ngFor="let brand of allMakes">
{{ brand.brand }}
</option>
</select>
ts file
this.allMakes = [{
id: '1',
brand: 'Mazda'
},
{
id: '2',
brand: 'Audi',
}];
这一切都是在我从 Angular 5 升级到 Angular 6 后开始的
控制台日志错误
ERROR Error: ngIfElse must be a TemplateRef, but received 'true'.
at Vt (main.6e360f04b7d39ee1dc33.bundle.js:1)
at t.set [as ngIfElse] (main.6e360f04b7d39ee1dc33.bundle.js:1)
at Sa (main.6e360f04b7d39ee1dc33.bundle.js:1)
at main.6e360f04b7d39ee1dc33.bundle.js:1
at main.6e360f04b7d39ee1dc33.bundle.js:1
at es (main.6e360f04b7d39ee1dc33.bundle.js:1)
at Os (main.6e360f04b7d39ee1dc33.bundle.js:1)
at Object.updateDirectives
(main.6e360f04b7d39ee1dc33.bundle.js:1)
at Object.updateDirectives (main.6e360f04b7d39ee1dc33.bundle.js:1)
at ts (main.6e360f04b7d39ee1dc33.bundle.js:1)
For ngIf
与 else 块你需要使用<ng-template>
作为 else 中的块.html
file.
这是示例代码:
<div *ngIf="condition; else elseBlock">Content to render when condition is true.</div>
<ng-template #elseBlock>Content to render when condition is false.</ng-template>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)