Angular 6 ng build --prod 错误“错误错误:ngIfElse 必须是 TemplateRef,但收到了‘true’。”

新手上路,请多包涵

错误错误: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>

文件

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)

原文由 Gerald Mathabela 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 704
2 个回答

问题已解决,原因是附加到“ng-template”的冗余属性(Bool)

 noData: boolean = true;
<ng-template #noData>...Blah blah...</ng-template>

原文由 Gerald Mathabela 发布,翻译遵循 CC BY-SA 4.0 许可协议

对于 ngIf 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>

原文由 Ramin Ar 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题