1

i use input with checkbox type to narrow my search result; problem is i put the checkboxes in to the modal and when i checked many of them and close the modal the checked inputs become unchecked .

and i want every time that i open the modal input checked been checked.

 var filterTemps = [
        "partial/uicomponent/mdlFilters/mdl.estateType.filter.html",
    ];

    $scope.showReleventMdl = function(num){

        var filtersModal = $modal({
            backdrop:true,
            placement:'top',
            templateUrl :  filterTemps[num],
            controller : 'filterCtrl',
            show: false
        });

        filtersModal.$promise.then(filtersModal.show);
    };
<!-- trigger the function for call modal -->
 <ul class="nav navbar-nav">
   <li>
     <a href="" ng-click="showReleventMdl(0)" ng-bind="string.pages.form.estateType"></a>
     </li>
   ...
</ul>
--------------------------------------------------
<!-- my Modal Template -->
<div class="modal-body">

                <ul class="filterList">
                    <li class="filterListItem half" ng-repeat="item in string.pages.mainPage.estateTypes">
                        <input id="estateType{{$index}}" ng-click="checked(item)" type="checkbox" class="filterCheck">
                        <label for="estateType{{$index}}" ng-bind="item"></label>
                    </li>
                </ul>

            </div>

i want to know is there any way to store checked inputs and bring them back in checked state with modal ? TNKS a lot

Amir Rezvani
  • 1,262
  • 11
  • 34

1 Answers1

0

You are not setting any values to a $scope object. Try this...

<div class="modal-body">    
  <ul class="filterList">
    <li class="filterListItem half" ng-repeat="item in string.pages.mainPage.estateTypes">
      <input id="estateType{{$index}}" type="checkbox" ng-model="checkbox[$index].checked" class="filterCheck">
      <label for="estateType{{$index}}" ng-bind="item"></label>
    </li>
  </ul>

</div>

Then, in your controller, you can set up the $scope object for your checkbox values.

$scope.checkbox = {};
buzzsaw
  • 1,476
  • 1
  • 10
  • 14
  • i know what you talking about but the problem is when i click the button to show the modal my controller call again and the default values are set because i define my variables inside this controller. – Amir Rezvani Oct 19 '15 at 06:57
  • @AmirRezvani Then you know exactly how to fix the problem. If you put the default data into a private variable, you can compare that against the $scope variable created in the parent controller to store the user input. If the user input variable is empty or undefined because they haven't opened the modal before, populate it with the private variable data. – buzzsaw Oct 19 '15 at 15:07
  • Ya, i put those variables in sessionStorge ! TNKS – Amir Rezvani Oct 20 '15 at 09:08