Logic for the Next button for the questionnaire?

前端 未结 3 1360
伪装坚强ぢ
伪装坚强ぢ 2021-02-15 02:21

I am beginner in AngularJS and facing some issues. I am trying to make a questionnaire having 1 question on each page. On every Next button data is save in the database. I am tr

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-15 02:40

    You could save your showDiv booleans in an array, and keep the corresponding index in memory. So something like this:

    $scope.currentState = 0;
    
    //ordered representation of possible states
    $scope.stateArray = [true, false, false, false, false];
    
    $scope.next = function(){
    
      //on to the next showDiv
      currentState++;
    
      stateArray.forEach(function(index, state){
    
        //hide everything else.
        if(index != currentState){
          state = false;
        }
        else{
          state = true;
        }
      }
    }
    

    Then, in your html, do ng-show="stateArray[currentState]"

    You'll inadvertently gain a "previous" function from this if you choose by decrementing the currentState instead.

提交回复
热议问题