Comment corriger Angular Parser Error: Private identifiers are not supported. Unexpected private identifier: ...

Problème :

En essayant d’exécuter notre application Angular, vous voyez l’erreur suivante :

error_message.txt
Error: src/app/my-component.html:18:31 - error NG5002: Parser Error: Private identifiers are not supported. Unexpected private identifier: #noName

lié à un source tel que

ngif_private_identifier_bad.html
<span *ngIf="name ; else #noName">
    {{name}}
</span>
<ng-template #noName>
    <span><i>Name not configured</i></span>
</ng-template>

Solution

Dans la clause ; else #noName, supprimez le caractère # => ; else noName pour corriger l’erreur :

ngif_private_identifier_fixed.html
<span *ngIf="name ; else noName">
    {{name}}
</span>
<ng-template #noName>
    <span><i>Name not configured</i></span>
</ng-template>

Consultez les articles similaires par catégorie : Angular Typescript