Praveen Jain
Praveen Jain

Reputation: 77

How to get id of md-select in javascript?

<div ng-repeat="(key, value) in dataSet | groupBy: 'partner.partnerName'"> 
  <md-select ng-model="selectedUserName"  id="myctrl"  placeholder="{{ key }}" class="partnerUserList" ng-change="myChange($id)"> 
    <md-option value="{{null}}">{{ key }} </md-option>
    <md-option ng-repeat="chatMsg in value" value="{{chatMsg.role.userId}}">{{ chatMsg.role.userId }} </md-option>
  </md-select>
</div>

i am creating the md-select control in a loop , now when i click on a particular drop down list i need to reset all drop down list . How can i achieve this ? how can i get ID of selected drop down list ? i tried passing this from HTML page but not getting the ID ?

Upvotes: 0

Views: 853

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222582

Pass the model variable and get the id in the controller

 <md-select ng-model="selectedUserName"  id="myctrl"  placeholder="{{ key }}" class="partnerUserList" ng-change="myChange(selectedUserName)"> 
    <md-option value="{{null}}">{{ key }} </md-option>
    <md-option ng-repeat="chatMsg in value" value="{{chatMsg.role.userId}}">{{ chatMsg.role.userId }} </md-option>
  </md-select>

Controller:

myChange = function(user){ 
  var id = user.role.userid //whatever id ;
}

Upvotes: 1

Related Questions