Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6 ng build --prod error "ERROR Error: ngIfElse must be a TemplateRef, but received 'true'."

ERROR Error: ngIfElse must be a TemplateRef, but received 'true'

HTML File

<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',
}];

It all started right after i upgraded from Angular 5 to Angular 6

Console Log Error

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)
like image 945
Gerald Mathabela Avatar asked Oct 15 '18 15:10

Gerald Mathabela


1 Answers

For ngIf with else block you need to use <ng-template> block as a else in your .html file.

Here is the sample code:

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

like image 91
Ramin Ar Avatar answered Sep 19 '22 13:09

Ramin Ar