AngularJS NG选项与NG模型不结合



这里有类似的问题,但我仍然不知道我在做什么错。我有ng选选项,填充一个形式的标签。在我委托时,在表单的提交控制器中。我感谢任何帮助。

<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);

它显示不确定,因为您编写了ng模型名称。ng模型名称应该是"选定的deducation",而不是console中的"教育" -

console.log("教育:" $ 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>

最新更新