2017-12-16 2 views
0

각도에 관한 질문이 있습니다. 나는이 두 개의 선택 필드가 있고 첫 번째 선택 필드의 선택한 옵션으로 두 번째 선택 필드의 결과를 으로 필터링하고 싶습니다. A1과 A2는 텍스트 일뿐입니다. secObj도 텍스트입니다. 따라서 A1을 먼저 선택한 경우 select-field 2에서 모델 이름이 A2 인 모든 모델이 결과에 있어야합니다.HTML 및 각도 : 선택에 따라 다름 선택

나는 인터넷의 많은 근원을 시도했지만 아무런 효과가 없었다.

감사합니다.

<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> 
+0

당신은 당신의'models' 배열과 같은 모양을 게시 할 수 있을까요? – Alex

답변

1

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

+0

감사합니다. 더 쉽게 할 수 있습니까? – KSV97

+0

Play with Object..it는 더 많은 작업을 단순화합니다 .. 더 쉬운 방법입니다 –

+0

OP가 각도 2+처럼 보이는 템플릿을 게시했다고 생각합니다. –

관련 문제