I have the following block of template code in Angular 9, with a condition to show either a view (eye) icon or an edit (pencil) icon. As you can see, much of the HTML is identical, with only a few attributes and the click binding that are different.
<button *ngIf="!(hasEditAccess$ | async)" type="button" class="icon-button" (click)="entityViewClicked()" aria-label="View">
<i class="far fa-eye" aria-hidden="true" title="View"></i>
</button>
<button *ngIf="hasEditAccess$ | async" type="button" class="icon-button" (click)="entityEditClicked()" aria-label="Edit">
<i class="fas fa-pencil-alt" aria-hidden="true" title="Edit"></i>
</button>
Without creating a new component, is there a cleaner way to write this HTML and the conditional statement once, rather than repeating so much of it?
I'm thinking this may involve {{ interpolation }} syntax and some kind of template variable, but I welcome any approach that reduces the code duplication.
.pipe(share());share()operator before. I'll have to dig into it. Thanks!