0

I have a Multiselect dropdown list in AngularJS. trying to set the selected values in edit mode. I tried multiple ways but not binding. Here is the code.

<div class="main-container department-dropdown">
                            <div class="form-group">
                                <label>All Practice/Department</label>
                                <div class="select-box">
                                    <select class="form-control searchabledropdown select2 practiceModelID"
                                            title="Select Practice/Department"
                                            id="settingpracticeModelID"
                                            ng-model="Dropdownmodel "
                                            ng-options="pra.PracticeID as pra.PracticeName for pra in AllDataDropdown " multiple>
                                    </select>
                                </div>
                            </div>
                        </div>

Drop Down list Loading code.

$scope.Dropdownmodel = "";
$scope.AllDataDropdown = [];
$scope.FetchAllPracticeDetails = function (ID) {
    //practice
    $scope.AllDataDropdown.push({
        PracticeID: "-1",
        PracticeName: "--Select Practice/Department--"
    });
    $scope.Dropdownmodel = $scope.AllDataDropdown[0].PracticeID;
    var data;
    var index = 0;
    $http.post(Testcontroller + '/FetchDropdownDetails/', data, { headers: headers }).then(function (rep) {
        
            for (var i = 1; i < rep.data.length; i++) {
                $scope.AllDataDropdown.push({
                    PracticeID: rep.data[i].ID,
                    PracticeName: rep.data[i].Name
                });
            
        }

    });
};

Below is the binding code i have used for binding selected dropdown list values.

    $http.post(Textcontroller + '/GetDetails/', Outputdata, { headers: headers }).then(function (rep) {
        $scope.selectedPractice = [];

        if (rep.data != null && rep.data.length > 0) {
            for (var i = 0; i < rep.data.length; i++) {
               

                //$scope.selectedPractice.push({
                //    PracticeID: rep.data[i].PracticeId,
                //    PracticeName: rep.data[i].Practice_Name
                //});
                
                var practiceval = rep.data[i].PracticeId;
                
                $.each(practiceval.split(","), function (i, e) {
                    $("#settingpracticeModelID option[value='" + e + "']").prop("selected", true);
                });
              

            }
      }
            
    });

Could you please any one help me how to bind the selected values to muliselected dropdwon list

Lakshm
  • 67
  • 1
  • 8

0 Answers0