使用angularJS在HTML表格上选择选项

时间:2018-07-29 18:13:05

标签: javascript angularjs ng-options angularjs-select

使用angularJS创建选择选项时遇到问题。为什么在表HTML的<th>元素上创建模型时未定义模型。但是,当我在表元素外部创建模型时,将定义模型,以使我在表元素上创建选择时如何定义模型。请帮忙。 谢谢

var myApp = angular.module("myModule", []);

myApp.controller("DefectController", ['$scope', function ($scope) {
 
 $scope.PhaseData = [{PhaseID:"PH001",PhaseName:"SIT"},{PhaseID:"PH002",PhaseName:"UIT"}];
 $scope.filterDefectByPhase = function () {
        console.log($scope.optPhase);
    }

}]);
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular.min.js"></script>
</head>

<body ng-app="myModule" ng-controller="DefectController">
<table>
<thead>
<tr>
<th>
<select class="form-control"
        ng-model="optPhase"
        ng-options="y.PhaseName for (x, y) in PhaseData"
        ng-change="filterDefectByPhase()">
</select>
<th>
</tr>
</thead>
</table>
</body>
</html>

0 个答案:

没有答案