1

I've md-select with multiple options enabled. By default ng-model of md-select does have one OBJECT value as array element.

on click/on selection of md-option - I want to update ng-model of md-select (Parent md-select)

<md-input-container class="md-block">
<md-select ng-model="selected_item" ng-model-options="{trackBy: \'$value.id\'}" multiple>
    <md-option ng-value="item" ng-click="onSelectItem(item)" ng-repeat="item in items">{{item.name}}</md-option>
</md-select>

Kyle Krzeski
  • 6,183
  • 6
  • 41
  • 52
Enigma
  • 749
  • 1
  • 13
  • 35

1 Answers1

0

What you're asking for happens automatically for you. When you set md-select as multiple, the ng-model will be an array of the selected items. See the "Option Groups" demo at https://material.angularjs.org/latest/demo/select for an example. You can select multiple toppings for your pizza and no extra code is needed to push those values into the model array.

adam0101
  • 29,096
  • 21
  • 96
  • 174
  • adam0101 - Yeah That's right but before selected elements gets pushed to ng-model of md-select, I just want to apply custom logic on selected elements (array). How can I do that ? – Enigma Jul 13 '17 at 07:44
  • What if you want one option selected atleast – Mustafa Jun 14 '22 at 03:30