1

I'm trying to make a <select> behave with single or multiple selection depending on a condition. So far I have tried:

<select ng-model="data.model" ng-attr-multiple="{{myCondition ? '' : undefined}}"> 

(here's a plnkr I have been testing with https://plnkr.co/edit/ACKBMZSJc2MVSJaDBGMY?p=preview)
But it won't work. Even leaving ng-attr-multiple alone won't work. What am I missing here?

1

1 Answer 1

6

https://docs.angularjs.org/error/$compile/selmulti

Binding to the multiple attribute of select element is not supported since switching between multiple and single mode changes the ngModel object type from instance to array of instances which breaks the model semantics.

If you need to use different types of select elements in your template based on some variable, please use ngIf or ngSwitch directives to select one of them to be used at runtime.

Sign up to request clarification or add additional context in comments.

2 Comments

Very well explained. This is what I was looking for. I guess there's no other way than using <select ng-if="multipleCondition" multiple> or a switch.
Thanks mate, this was driving me nuts!