$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>
&#13;
我尝试使用md-select选择框,但ng-model似乎不起作用。我知道哪里出错了?
ng-change功能的输出是未定义的。
答案 0 :(得分:1)
使用$scope.modelData
代替modelData
$scope.modelData;
$scope.callFunction = function() {
console.log($scope.modelData);
}
&#13;
<md-select ng-model="modelData" ng-change="callFunction()">
<md-option ng-repeat="x in tempData" ng-value="x">{{x}}
</md-option>
</md-select>
&#13;
答案 1 :(得分:1)
可以通过控制器$scope
$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);
}
&#13;
<md-select ng-model="modelName" ng-change="callFunction()">
<md-option ng-repeat="x in tempData" ng-value="x">{{x}}
</md-option>
</md-select>
&#13;
答案 2 :(得分:0)
是否正在记录"undefined"
?可能会更好地使用console.log($scope.modelData);
答案 3 :(得分:0)
您必须在控制器功能中添加$ scope。
angular.module('test')
.controller('TestController',['$rootScope','$http','$scope',
function ($rootScope,$http, $scope) {
$scope.callFunction = function() {
console.log($scope.modelData);
}
}])