Search code examples
angularjsdrop-down-menuangularjs-material

AngularJS Material: Cannot get value of md-select


I've got a AngularJS Material Select:

       <md-input-container style="margin-right: 10px;">
            <label>Roll</label>
            <md-select id="acc-type" required="" ng-model="rolle">
                <md-option ng-selected="true" value="Tenant">Tenant</md-option>
                <md-option value="Lessor">Lessor</md-option>
            </md-select>
        </md-input-container>

and I want to get the actual selected option. I tried it with

    var e = document.getElementById("acc-type");
    var selectedItem = e.value;

but all I receive is undefined. Is there any option to get the value of a md-select in AngularJS?


Solution

  • Since you have already defined ng-model="rolle" in your md-select, you can access it via $scope.rolle

    Try:

    var selectedItem = $scope.rolle