这里有类似的问题,但我仍然无法弄清楚我做错了什么。我有ng-options填充表单中的标签。在我的console.log中,在表单的提交控制器中,ng-model返回undefined。我很感激任何帮助。
<label ng-controller="educationController">
select your level of education
<select ng-model="selectedEducation" ng-options="education for education in degrees" required>
</select>
</label>
这是控制器
angular.module('drsApp.reviewerApplication');
app.controller('educationController', educationController)
function educationController($scope){
$scope.degrees=[
"Bachelor Degree",
"Master Degree",
"Doctorate Degree"
]
};
这是形式的控制器
console.log("education: "+ $scope.selectedEducation);
答案 0 :(得分:0)
它显示未定义,因为您写的ng-model名称错误.ng-model名称应为&#34; selectedEducation&#34;而不是&#34;教育&#34;比如在控制台 -
console.log(&#34; education:&#34; + $ scope.selectedEducation);
你可以在这里查看 -
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="educationController">
select your level of education
<select ng-model="selectedEducation" ng-options="education for education in degrees" required>
</select>
<button ng-click="formSubmit()">Submit</button>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('educationController', function ($scope) {
$scope.degrees=[
"Bachelor Degree",
"Master Degree",
"Doctorate Degree"
];
$scope.formSubmit=function (){
console.log("education: "+ $scope.selectedEducation);
}
});
</script>
</body>
</html>
&#13;