0

hi all i am using angularjs ng-repeat i have checkbox and dropdown in inside the repeat now my need is when check the checkbox value i want bind the dropdown but now when i check the checkbox all dropdown values are changed but my need i want bind the dropdown based checkbox help how to solve

ng-repeat code

 <div ng-repeat="BFMaterialStream in BFMaterialStreams">
   <input type="checkbox" ng-change="checkchange(BFMaterialStream.MaterialStream,$index)"
   ng-model="selection.ids[BFMaterialStream.MaterialStream]" name="group" id="BFMaterialStream.MaterialStream" />
    {{BFMaterialStream.MaterialStream}} 
        <select id="MaterialElevator" tabindex="7" required typeof="text" name="Elevator"
         form="DistanceMatrixFormId" class="form-control" 
          ng-model="ViewGetBUMaterialStream.ToElevator"
     >
     <option value=''>Select</option>
     <option ng-repeat="ViewGetBUMaterialStream in ViewGetBUMaterialStreams "
      value="{{ViewGetBUMaterialStream.ToElevator}}"
      >
     {{ViewGetBUMaterialStream.ToElevator}}
    </option>
     </select>
       </div>

check change time bind code

$scope.checkchange = function(Stream, index) {
     $http.get('/ViewGetBUMaterialStream/' + Stream ).then(function (response) {
           $scope.ViewGetBUMaterialStreams = response.data;
     });
}

2 Answers 2

1

Make $scope.ViewGetBUMaterialStreams as an array.

In HTML change the repeat as

<option ng-repeat="ViewGetBUMaterialStream in ViewGetBUMaterialStreams[$index]"
      value="{{ViewGetBUMaterialStream.ToElevator}}">

In change your $scope.ViewGetBUMaterialStreams = response.data assignment as $scope.ViewGetBUMaterialStreams[index] = response.data

JS looks like this:

$scope.ViewGetBUMaterialStreams = [];
$scope.checkchange = function(Stream, index) {
     $http.get('/ViewGetBUMaterialStream/' + Stream ).then(function (response) {
           $scope.ViewGetBUMaterialStreams[index] = response.data;
     });
};
Sign up to request clarification or add additional context in comments.

6 Comments

super Thanks Mr.Amir Suhail.i am tried that way but i forgot to scope into array
No problem. Just a pointer, always its a best pratice to use ng-options instead on ng-repeated <option>
another query when i select dropdown i need suto auto check in checkbox
what is main difference option and repeat
The main difference is when the select model bound to a non-string value, option wont able to repeat that. See docs docs.angularjs.org/api/ng/directive/select
|
0

You may want to use ng-options directive:

<select ng-model="ViewGetBUMaterialStream.ToElevator"
        ng-options="stream.ToElevator as stream for stream in ViewGetBUMaterialStreams">
     <option value=''>Select</option>
</select>

Here is a JSFiddle of a simple use case of ng-options

1 Comment

same yar because of ngrepeat ervery time i have to check the checkbox value will change all drop down

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.