我有一个文本框和一个下拉列表。文本框值,我正在显示我从响应中得到的任何内容。
例如,
下拉值是,
$ scope.newPlan = [" A","我"," B"," II"," C& #34;" III"];
我的文本框值为" A"。条件是,如果我的文本框值是" A",我只需要显示"我"在下拉列表中剩下的我不想表现出来。与,
相同" A" - > " I"
" B" - > " II"
" C" - > " III"
我正在使用angularjs。如何在下拉列表中显示此内容。
It is ahowing all the values.
$scope.newPlan = ["A", "I", "B", "II", "C", "III"];
$scope.textboxValue = "A";
if ($scope.existingPlan == "A") {
$scope.gpasPlan = $scope.newPlan[1];
} else if ($scope.existingPlan == "B") {
$scope.gpasPlan = $scope.newPlan[3];
} else if ($scope.existingPlan == "C") {
$scope.gpasPlan = $scope.newPlan[5];
}

<select required name="selectnewPlan" ng-model="gpasPlan" ng-options="item for item in newPlan">
<option value="">--Choose New Plan--</option>
</select>
&#13;
我该怎么做..
答案 0 :(得分:0)
这可以帮助你:)
<!DOCTYPE html>
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<input type="text" ng-change="changeDropdownValue(existingPlan)"
ng-model="existingPlan"> <select ng-model="selectedName"
ng-options="x for x in newPlan">
</select>
</div>
<script>
var app = angular.module( 'myApp', [] );
app.controller( 'myCtrl', function ( $scope ) {
$scope.changeDropdownValue = function ( data ) {
$scope.newPlan = [
"A", "I", "B", "II", "C", "III"
];
if ( $scope.existingPlan == "A" ) {
$scope.selectedName = $scope.newPlan[ 1 ];
$scope.newPlan = $scope.newPlan[ 1 ];
console.log( $scope.newPlan );
} else if ( $scope.existingPlan == "B" ) {
$scope.selectedName = $scope.newPlan[ 3 ];
$scope.newPlan = $scope.newPlan[ 3 ];
} else if ( $scope.existingPlan == "C" ) {
$scope.selectedName = $scope.newPlan[ 5 ];
$scope.newPlan = $scope.newPlan[ 5 ];
}
}
} );
</script>
</body>
</html>