2016-12-07 7 views
0

だから私は持っていたこのHTML状況

<ion-view title="Question# {{questionNo}}"> 
    <ion-nav-bar class="bar bar-header bar-dark"> 
    </ion-nav-bar> 

<ion-content class="quest-container"> 
    <h2>{{question}}</h2> 
    <ol> 

    </ol> 
    <br> 
    <a class="button-assertive button" href="#/{{questionNo + 1}}" ng-disabled="nextRoute()">Next</a> 
    <a class="button-energized button" ui-sref="score" ng-disabled="!nextRoute()">Finish</a> 
</ion-content> 

それはこのように現れる:

Screenshot

とコントローラとJSONデータベース:次に

.controller('questionController',function($scope, $stateParams, $state){ 
    $scope.questions = [ 
    { 
     nama:"What is your name?", 
     answers:['Ahmed','Saad','Farhan'], 
     correctAnswer:2 
    }, 
    { 
     nama:"How old are you?", 
     answers:['22','23','24'], 
     correctAnswer:3 
    }, 
    { 
     nama:"Where do you live?", 
     answers:['Karachi','lahore','Islamabad'], 
     correctAnswer:1 
    }, 
    { 
     nama:"How many apps you have developed?", 
     answers:['<10','10','>10'], 
     correctAnswer:2 
    }, 
    { 
     nama:"Which car you have?", 
     answers:['Chevrolet','Mercedes Benz','Toyota','Tesla'], 
     correctAnswer:2 
    } 

]; 

    $scope.nextRoute = function(){ 
     if(parseInt($stateParams.questionId) +1 > $scope.questions.length){ 
      return true; 
      console.log("disable"); 
     } 
     else{ 
      console.log("enable"); 
      return false; 
     } 
    } 

    $scope.questionNo = parseInt($stateParams.questionId); 
    $scope.question = $scope.questions[parseInt($stateParams.questionId) - 1].nama; 
    $scope.answers = $scope.questions[parseInt($stateParams.questionId) - 1].answers; 
    $scope.totalQuestions = $scope.questions.length; 
    $scope.currentRoute = parseInt($stateParams.questionId); 

    function answerChoice(){} 

}); 

Iいくつかの移行データバを行ったSE FirebaseにQuestionsテーブルに格納されている、と私はこのようデータベースを呼び出すために試したどの:

$scope.questions = $firebaseArray(fireBaseData.refQuestions()); 

$scope.nextRoute = function(){ 
    // i dont know how to replace parseInt($stateParams.questionId) with my fireBaseData, and also call $scope.questions.length) 
    if(parseInt($stateParams.questionId) +1 > $scope.questions.length){ 
     return true; 
     console.log("disable"); 
    } 
    else{ 
     console.log("enable"); 
     return false; 
    } 
} 

// didnt work using this syntax 
$scope.questionNo = $scope.questions.$id; 
//also these kind parseInt and $stateParams things 
$scope.question = $scope.questions[parseInt($stateParams.questionId) - 1].nama; 
$scope.answers = $scope.questions[parseInt($stateParams.questionId) - 1].answers; 
$scope.totalQuestions = $scope.questions.length; 
$scope.currentRoute = parseInt($stateParams.questionId); 

//the rest i think i could work on it if i got the answer for questions above 
function answerChoice(){} 

私の質問は以下のとおりです。

  1. 私は私がいた(私のFirebaseテーブルIDを呼び出すにはどうすればよいです前にparseInt($stateParams.questionId)を使用して)?
  2. データベースの長さを前と同じようにカウントするにはどうすればよいですか(以前はparseInt($stateParams.questionId)を使用していましたが、現在は0とカウントされています)。この構文を使用して

答えて

0

てみ

$scope.questions.$loaded().then(function() { 
    // didnt work using this syntax 
    $scope.questionNo = $scope.questions.$id; 
    //also these kind parseInt and $stateParams things 
    $scope.question = $scope.questions[parseInt($stateParams.questionId) - 1].nama; 
    $scope.answers = $scope.questions[parseInt($stateParams.questionId) - 1].answers; 
    $scope.totalQuestions = $scope.questions.length; 
    $scope.currentRoute = parseInt($stateParams.questionId); 
}); 
+0

私はこれを試してみたが、私は少し混乱し、それがテーブルからfirebaseデータを呼び出すための部分であるを得ましたか。 –

関連する問題