1

在这里,我基本上设置了 3 个选择列表

<label for="organization">Organization</label>
<select ng-change="setOrganization()" ng-model="form.organization" 
        ng-options="o.name as o.displayName for o in organizations" required></select>

<label for="board">Board</label>
<select ng-change="setBoard()" ng-model="form.board" 
        ng-options="b.id as b.name for b in boards" required></select>

<label for="board">List</label>
<select ng-change="setList()" ng-model="form.list" 
        ng-options="l.id as l.name for l in lists" required></select>

JS:

$scope.setOrganization = function(){
    $scope.lists = {};

    mySerivce.get('....', function(boards){
        $scope.boards = angular.fromJson(boards);
        $scope.$apply();
    });
};

$scope.setBoard = function(){
    mySerivce.get('...', function(lists){
        $scope.lists = angular.fromJson(lists);
        $scope.$apply();
    });
};

因此,当一个组织被选中时,我会得到板子并用板子数据填充第二个选择字段。Again when a board is selected all lists assigned to the board are fetched and the third select field is set with this data. 在所有选择字段都具有选定值之前,表单将保持无效。

当用户更改组织时,所有字段都会被清除。但是 form.$valid 对象仍然是 true。问题出在哪里?当没有选择任何值时,表单必须是无效的,因为这些字段是必需的。有任何想法吗?

4

1 回答 1

1

试试这个,它将验证选择值未设置。很高兴它奏效了。

mySerivce.get('....', function(boards){
    $scope.boards = angular.fromJson(boards);
    $scope.form.board = null;
    $scope.$apply();
});
于 2013-09-13T16:42:56.100 回答