Remember checkbox in slice function using angular pagination

Hey I have one question about using slice in pagination and about indexes checkbox in angular, so in undermentioned code I can create new new question on click and create new chceckbox in question (for example simple quiz create question and next create boolean answer). My problem is when I create more than two questions (two questions in one page in pagination) and check answers in checkbox and go to next page and back to first page my answers (checked checkboxes clear). My question is how to remember checked checkbox going through pages in pagination ? I thought if I use index everything will works ok, but not.

angular.module('myApp', ['ui.bootstrap'])

.controller('myCtrl', function($scope){
  $scope.currentPage = 2;
  $scope.itemsPerPage = 2; 
  $scope.questionQuiz = [];
  $scope.addQuizQuestion = function(){
    $scope.questionQuiz.push({answers: []});
    $scope.totalItems = $scope.questionQuiz.length;
  $scope.input = {}
   $scope.addAnswer = function (question){
  cursor: pointer
  display: block
<script src=""></script>
<script src="//"></script>
<script src="example.js"></script>
<link href="//" rel="stylesheet">
<link href="" rel="stylesheet">
<body ng-app="myApp" ng-controller="myCtrl">
  <a class="input-group-addon" ng-click="addQuizQuestion()">
    <i class="fa fa-plus"></i>&nbsp;Add question
  <div ng-repeat="question in questionQuiz.slice(((currentPage-1)*itemsPerPage), ((currentPage*itemsPerPage))) track by $index">
   <label><h3>Question {{$index + 1 + (currentPage-1)*itemsPerPage}}</h3></label>                      
   <input type="checkbox" ng-model="input[$index + (currentPage-1)*itemsPerPage][0]" class="form-control">
   <div class="input-group-addon add-field-answer">
     <a ng-click="addAnswer(question)" title="Dodaj nową odpowiedź">
      <i class="fa fa-plus"></i>
   <div ng-repeat="answer in question.answers track by $index">
       <input type="checkbox" ng-model="input[$parent.$index + (currentPage-1)*itemsPerPage][$index + 1]" class="form-control">
  <pagination total-items="totalItems" ng-model="currentPage" class="pagination-sm text-center" items-per-page="itemsPerPage" previous-text="Prev" next-text="Next"></pagination>

1 answer

  • answered 2018-01-11 20:55 Mat.Now

    I solved problem, just I should create empty object in controller $scope.input={} and connect with mgModal