gpt4 book ai didi

javascript - HTML 和 Angular : Select depends on other select

转载 作者:行者123 更新时间:2023-12-03 02:51:19 25 4
gpt4 key购买 nike

我有一个关于 Angular 小问题。我有这两个选择字段,我想过滤结果第二个选择字段的选定选项与第一个选择字段的选定选项。 A1和A2只是文本。 secObj 是还有文字。因此,如果首先选择 A1,则在选择字段 2 中,所有模型名称为 A2 的模型都应该出现在结果中。

我尝试了许多互联网来源,但没有任何效果。

谢谢!

<div class="test">
<select class="form-control" name="testA" id="123">
<option>A1</option>
<option>A2</option>
</select> </div>

<div class="test2">

<select class="form-control" name="testB" id="456">

<option *ngFor="let model of models| filter: {modelname: ?? A1. or A2 ??} ;trackBy: trackId "> {{model.id}}

</option>

</select></div>

最佳答案

angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope) {
$scope.item = ['A1','A2','A3']
$scope.selected_item = 'A1'
$scope.sub_item = {'A1':[1,2,3,4,5],'A2':[4,5,6],'A3':[5,7,8]}
$scope.slected_sub_item = $scope.sub_item[$scope.selected_item]
$scope.selected_sub_item_selected = $scope.slected_sub_item[0]
$scope.update= function(key) {
$scope.selected_item = key;
$scope.slected_sub_item = $scope.sub_item[$scope.selected_item]
$scope.selected_sub_item_selected = $scope.slected_sub_item[0]

};
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp" ng-controller="myCtrl">
<select ng-options="val for val in item" ng-change="update(selected_item)" ng-model="selected_item"></select>
<select ng-options="val for val in slected_sub_item" ng-model="selected_sub_item_selected"></select>
</body>

关于javascript - HTML 和 Angular : Select depends on other select,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47846394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com