Adding optional multiple attribute in Angular component

Viewed 191

I have an Angular component that contains a select element. In some cases I want the "multiple" attribute to be added to the element. Is there a way to add it conditionally?

1 Answers

For a select, conditionally enable the multiple as shown:

<md-select [formControl]="myForm" [multiple]="multiEnabled">

Your condition to enable or disable the attribute:

multiEnabled = false;

The above is for a Material select control.

Haven't tried it on other controls.

Related