0

모바일 시험용 앱을 만들고 있습니다. 질문은 객관식 유형입니다. 이전 및 다음 질문 버튼이 있습니다. $ state.go를 사용하여 동일한 HTML 페이지로 전환하지만 다른 질문과 선택 사항이 있습니다.각 상태입니다. 새로 고침하지 않으려면 선택한 라디오 버튼이 표시되지 않습니다.

// this function is in a service and the service is used by the controller 
this.switchTemplateHTML = function(type, category) { 
    if(type == "multiple") { 
     $state.go("test-item-multiple-choice", {categoryParam: category.category_name, questionPointer: self.questionIndexPointer}); 
    } 
} 

질문은 질문, 선택 사항 (배열) 및 사용자 응답 (선택 색인)을 포함하는 개체 배열에 저장됩니다. 이전 또는 다음 질문으로 이동하려면 컨트롤러에이 코드가 있습니다.

$scope.nextQuestion = function() { 
    if(service.questionIndexPointer+1 < $scope.questions.length) { 
     service.questionIndexPointer++; 
     service.switchTemplateHTML($scope.questions[service.questionIndexPointer].type, $scope.category); 
    } 
}; 

$scope.previousQuestion = function() { 
    if(service.questionIndexPointer > 0) { 
     service.questionIndexPointer--; 
     service.switchTemplateHTML($scope.questions[service.questionIndexPointer].type, $scope.category); 
    } 
}; 

컨트롤러 내에 $ scope.init 함수가 있습니다. scope.init는 다음 질문으로 갈 때마다 호출됩니다. $ stateParams.categoryParam에 따라 범주, 질문 및 선택 항목을로드합니다. 그들은 선택된 표시되지 않습니다, 나는 이미 대답 한 앞의 질문에 갈 때 :

// When clicking on a radio button choice, the answer to the current question is updated 
$scope.$watch('radioChoice.choice', function(newval, oldval) { 
     if(typeof newval != 'undefined') { 
      if($scope.currentQuestion != null) { 
       $scope.currentQuestion.usersAnswer = newval; 
      } 
     } 
    }); 
또한

이 :

// Watch the function that returns service.timerInString 
    // Directly watching service.timerInString doesn't work 
    $scope.$watch(function() { 
     return service.timerInString;  
    }, function(newval, oldval) { 
     $scope.time = newval; 

     // Not relevant 
     if(newval === "00:00") { 
      service.getCategory($scope.category.category_name).categoryIsFinish = true; 
      var alertTimeup = $ionicPopup.alert({ 
       template: '<center>Your time is up!</center>' 
      }); 
      alertTimeup.then(function(res) { 
       service.stopTimer(); 
       service.saveAnswersInCategory(); 
       $scope.time = '00:00'; 
       $state.go("home"); 
      }); 
     } 

     // I added this so that the radio button is SUPPOSED to be selected when going back to a question that has been answered 
     if(typeof $scope.currentQuestion.usersAnswer != 'undefined') { 
      $scope.radioChoice.choice = $scope.currentQuestion.usersAnswer; 
     } 
    }); 

이제 여기에 문제가 있어요 또한 그 안에이 코드입니다 (하지만 현재 console.log에 답변이있는 경우). 그러나 이미 답변 된 다음 질문으로 가면 선택한 대답이 표시됩니다. $ scope.init() 함수 안에 console.log를 넣었고 다음 질문 버튼을 클릭 할 때마다 콘솔에 출력하지만 이전 질문 버튼을 클릭 할 때 인쇄되지 않으므로 init() 함수를 의미합니다 갈 때 호출되지 않습니다. 어떻게 호출되지 않습니다, 나는 같은 state.go 질문 인덱스 포인터에서만 다릅니다. 나는 또한 (내가 조사한 바에 따라) state.go 매개 변수에 {reload:true, inherit:false}을 추가하려고 시도했지만 작동하지 않습니다.

답변

0

구성에 $ionicConfigProvider.views.maxCache(0);을 추가하십시오.

+1

이 질문에 대한 답변을 제공하지 않습니다. 비평하거나 저자의 설명을 요청하려면 게시물 아래에 의견을 남겨 둡니다. - [검토 중] (리뷰/저품절 게시물/13945362) –

+0

나는 저자입니다. – Zik

관련 문제