Is there a way to lint an Angular 4+ template to ensure all ng-template ids are unique?
Asked Answered
T

0

7

Angular 4+ provides a way to perform if/else logic in the template file, e.g.

<ng-container *ngIf="isSaveSuccess; else elseBlock">
  Save succeeded.
</ng-container>
<ng-template #elseBlock>
  Save failed.
</ng-template>

This, however, requires that you specify a unique ng-template id. We have some concern about accidentally introducing duplicate "elseBlock" templates with this approach, e.g.

<ng-container *ngIf="isSaveSuccess; else elseBlock">
  Save succeeded.
</ng-container>
<ng-template #elseBlock>
  Save failed.
</ng-template>
...
<ng-container *ngIf="isUpdateSuccess; else elseBlock">
  Update succeeded.
</ng-container>
<ng-template #elseBlock> <!-- duplicate id -->
  Update failed.
</ng-template>

Is there a way to lint the Angular template files to detect duplicate ng-template ids?

Trifolium answered 8/12, 2017 at 20:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.