Frank Jusnes
Frank Jusnes

Reputation: 185

Adding optional multiple attribute in Angular component

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?

Upvotes: 1

Views: 707

Answers (1)

Andrew Halil
Andrew Halil

Reputation: 1323

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.

Upvotes: 1

Related Questions