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

Ger*_*ela 5 javascript typescript angular6

错误错误: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>
Run Code Online (Sandbox Code Playgroud)

ts文件

  this.allMakes = [{
    id: '1',
    brand: 'Mazda'
  },
  {
    id: '2',
    brand: 'Audi',
  }];
Run Code Online (Sandbox Code Playgroud)

我从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)
Run Code Online (Sandbox Code Playgroud)

Ger*_*ela 10

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

noData: boolean = true;
<ng-template #noData>...Blah blah...</ng-template>
Run Code Online (Sandbox Code Playgroud)


Ram*_* Ar 8

对于ngIfelse块,您需要<ng-template>.html文件中将block用作else 。

这是示例代码:

<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>