-1

I am brushing up my Angular knowledge and I came across an "else" to use if ngIf. In reality I think it is easier to use "valor !== false" to simulate an else. But if I need to give assistance in a code that uses I want to be prepared.

<div *ngIf="valor === 'teste'; else showOther">tttt</div>

<ng-temlate #showOther>
  <ng-content> outro </ng-content>
</ng-temlate>

I get this

Type 'HTMLElement' is not assignable to type 'TemplateRef<NgIfContext<boolean>>'.

The code

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Diego Alves
  • 2,462
  • 3
  • 32
  • 65

1 Answers1

1

You wrote ng-temlate instead of ng-template.

But after fixing it, I still get this error:

Uncaught Error: Template parse errors: element cannot have content. (" <div *ngIf="valor === 'teste' ; else showOther">Hello! <ng-template #showOther> [ERROR ->]Content to render when condition is false.

Remove the ng-content tag, it will work. So the code should be:

<div *ngIf="valor === 'teste' ; else showOther">ttt</div>
<ng-template #showOther>
  Content to render when condition is false.
</ng-template>
UnitTset
  • 259
  • 1
  • 5