javascript - Angular 6 ng build --prod 错误“错误错误:ngIfElse 必须是 TemplateRef,但收到‘真’。”
问题描述
ERROR 错误:ngIfElse 必须是 TemplateRef,但收到“真”
HTML 文件
<select class="form-control">
<option selected value="0">Select Manufacturer</option>
<option *ngFor="let brand of allMakes">
{{ brand.brand }}
</option>
</select>
ts文件
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)
解决方案
对于ngIf
with else 块,您需要在文件<ng-template>
中将块用作 else 。.html
这是示例代码:
<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>
推荐阅读
- c - 编译正则表达式:出现成功错误
- android - Android Studio 在手机上运行时忽略 layout-large
- methods - 如何通过函数指针调用方法?
- javascript - 在函数中调用时变量始终未定义
- javascript - this.prop 上的多个 forEach 语句导致错误
- r - 替换数据框的子集
- python - 如何在“pyautogui”中循环并在循环中写入每个数字?
- r - 如何更好地分析“通话”的内容?
- php - 删除 mailchimp 活动 - 找不到资源
- sql-server - 如何在 2 个带有 GROUP 的 SELECT 语句之间创建 JOIN?