How to bind to multiple in md-select inside directive

前端 未结 1 1975
再見小時候
再見小時候 2021-01-24 10:20

Trying to create a simple directive that shows a textbox or dropdown depending on whether an array is passed for a model property on the scope.

Anything exc

1条回答
  •  庸人自扰
    2021-01-24 10:52

    Probably this is not the answer you are looking for...

    I've tried to conditionally set multiple attribute to md-select and nothing seems to be work (ng-attr-multiple, ng-multiple...). Probably it's an angular-material bug.

    So, as a workaround, you could conditionally add two md-selects, depending on the atribute model.multiSelect value: one with multiple attribute and the other one without it. Example:

    \
        \
         {{ item.label }}\
        \
    \
    \
        \
         {{ item.label }}\
        \
    \
    

    IMPORTANT: Keep in mind that if the md-select is multiple, the value binded needs to be an array, so you will have to change ng-model="value" per ng-model="[value]", as you can see in the previous code.

    I've forked your plunker and you can see a working example here

    Hope it helps. Anyway, I'll be waiting for other answers.

    0 讨论(0)
提交回复
热议问题