-2

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>
Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62
ziaulain
  • 94
  • 2
  • 11

1 Answers1

1

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.

Ravi Shankar Bharti
  • 8,922
  • 5
  • 28
  • 52
Sakky
  • 84
  • 10
  • I know about this. is there any work around? i want to use the same variable. – ziaulain Jun 09 '17 at 07:41
  • I am afriad, there is no work around for this, you have to use different variable names for the ng-model and the laguages array. BTW why do you want to use the same variable name? – Ravi Shankar Bharti Jun 09 '17 at 07:42
  • @Sakky this should be listed as a comment not an answer. To make this an answer, you should add some code supporting your solution. Please edit it, and add some code, and show the user how he can rectify the problem. – Ravi Shankar Bharti Jun 09 '17 at 07:44