Is it possible in Angular to only render an element attribute if it is defined?
If for example I have a button component
export class ButtonComponent {
/** The name id to be given to the button */
@Input() id: string;
/** The name to be given to the button */
@Input() name: string;
}
with a template of
<button
[id]="id"
[name]="name"
>
<ng-content></ng-content>
</button>
and if I pass it an id but not a name it renders a name attribute with a value of undefined.
<button _ngcontent-c1="" id="login" name="undefined">
Login
</button>
Is it possible to not render the name attribute at all if the name input is not supplied like below?
<button _ngcontent-c1="" id="login">
Login
</button>