使用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>