-1

$scope.callFunction = function() {
  console.log($scope.modelData);
}
<md-select ng-model="modelData" ng-change="callFunction()">
  <md-option ng-repeat="x in tempData" ng-value="x">{{x}}
  </md-option>
</md-select>

I'm trying to use the md-select select boxes but the ng-model doesn't seem to work. Any idea where I'm going wrong?

The output in ng-change function comes as undefined.

S Sharma
  • 9
  • 2

4 Answers4

1

use $scope.modelData instead of only modelData

$scope.modelData;
$scope.callFunction = function() {
  console.log($scope.modelData);
}
<md-select ng-model="modelData" ng-change="callFunction()">
  <md-option ng-repeat="x in tempData" ng-value="x">{{x}}
  </md-option>
</md-select>
chirag satapara
  • 1,947
  • 1
  • 15
  • 26
1

the models are accessible via $scope in the controller $scope.modelName

// sometime data might not bind for object in that case you to declare this not always 
$scope.modelName;
$scope.callFunction = function() {
  console.log($scope.modelName);
}
<md-select ng-model="modelName" ng-change="callFunction()">
  <md-option ng-repeat="x in tempData" ng-value="x">{{x}}
  </md-option>
</md-select>
Abdullah Al Noman
  • 2,817
  • 4
  • 20
  • 35
0

Is it logging "undefined"? probably would work better with console.log($scope.modelData);

Edorka
  • 1,781
  • 12
  • 24
0

You have to add $scope in controller function.

 angular.module('test')
    .controller('TestController',['$rootScope','$http','$scope', 
       function ($rootScope,$http, $scope) {
          $scope.callFunction = function() {
            console.log($scope.modelData);
        }
 }]) 
Nikita
  • 437
  • 2
  • 12