Search code examples
angularjsangularjs-materialmd-select

md-select same object in ng-option and ng-model


Is it possible to use same json object in ng-option and ng-model of md-select?

Here I'm using Angular Material md-select instead of HTML Select

Controller:

$scope.languages = [
     { name: 'English', value: true }, 
     { name: 'English', value: false }
];

View:

<md-select ng-model="languages"
             placeholder="Select"
             class="select-dropdown md-no-underline"
             multiple>
    <md-option ng-value="language.value" ng-repeat="language in languages">
      {{language.name}}
    </md-option>

</md-select>

Solution

  • It is so because when you select or un-select the list items from your md-checkbox it alters the list from which ng-repeat is getting values. You need to maintain the selections in another variable.