How to combine structural directive with ng-attr-*?

Viewed 46
<ng-container *privileges="updateName; else readOnlyName">
   <input clrInput [(ngModel)]="name" name="name" required/>
</ng-container>
<ng-template #readOnlyName>
   <input clrInput [(ngModel)]="name" name="name" required readonly/>
</ng-template>

This is a minimum example of my current code where users who have updateName privileges are able to see an editable input field. But as you can see the only difference in the blocks of code is one attribute readonly. Is there a way to avoid having two blocks of code for this?

I heard ng-attr-* might help with this but I'm not sure how it works together with structural directives.

1 Answers

If they are the same, why a simple condition on the readonly attribute is not suitable?

<ng-container *privileges="updateName">
   <input clrInput [(ngModel)]="name" name="name" required [readonly]="some_boolean_condition"/>
</ng-container>

OR put away ng-container entirely

<input *ngIf="some_condition_relate_to_privileges_updateName" clrInput [(ngModel)]="name" name="name" required [readonly]="some_boolean_condition"/>
Related