Angular JSのクイズアプリケーションに取り組んでいました。クイズアップアプリケーションのように、質問から構成されたタイムクイズがあります。私は質問に答えることができ、最後に結果を出すことができるクイズのアプリケーションを作ったが、自分の質問ごとにどのようにタイマーを導入できるのかという問題に悩まされていますか?別の指令やコントローラを作る必要がありますか?問題は、タイマーが遅延を作成する$タイムアウト関数を必要とするが、それは私のアプリケーション全体で遅延を作り出すことである。どんな助け?Angular JSアプリケーション用に10秒タイマーを作成
注:私はAngular JSの初心者です。
app.js:
var app = angular.module('TheQuiz',[]);
app.controller('QuizControl',['$scope','$http','$sce','$timeout',function($scope,$http,$sce,$timeout){
$scope.score = 0;
$scope.presentQues = -1;
$scope.presentQuesAnswered = 0;
$scope.percent = 0;
$scope.playername = $scope.playername;
$scope.myself = false;
$http.get('getdata.php').then(function(qData){
$scope.Questions = qData.data;
$scope.fullQuestions = $scope.Questions.length;
});
$scope.startQuiz = function(){
if ($scope.playername.length){
$scope.presentQues = 0;
}
}
$scope.restart = function(){
$scope.score = 0;
$scope.presentQues = -1;
$scope.presentQuesAnswered = 0;
$scope.percent = 0;
$scope.playername = "";
$http.get('getdata.php').then(function(qData){
$scope.Questions = qData.data;
$scope.fullQuestions = $scope.Questions.length;
});
}
$scope.selectAns = function(pIndex , rIndex){
var quesState = $scope.Questions[pIndex].quesState;
if (quesState != 'answered'){
$scope.Questions[pIndex].selectedAns = rIndex;
var rightAns = $scope.Questions[pIndex].correct;
$scope.Questions[pIndex].rightAns = rightAns;
if (rIndex === rightAns){
$scope.Questions[pIndex].correctness = 'correct';
$scope.score += 1;
}
else {
$scope.Questions[pIndex].correctness = 'incorrect';
}
$scope.Questions[pIndex].quesState = "answered";
}
$scope.percentage = (($scope.score/$scope.fullQuestions) * 100).toFixed(2);
}
$scope.yesselected = function(pIndex , rIndex){
return $scope.Questions[pIndex].selectedAns === rIndex;
}
$scope.yescorrect = function(pIndex , rIndex){
return $scope.Questions[pIndex].rightAns === rIndex;
}
$scope.Continue = function(){
return $scope.presentQues += 1;
}
$scope.Pass = function(){
return $scope.presentQues += 1;
}
}]);
感謝を参照することができます!私は私のアプリケーションでこれを使用しようとします。 –
もちろん、どのように乗り越えているか教えてください。もちろん、これはAngularを初めて使う人にとっては難しいことです。 Vikashで提案されているようにプラグインを使用することは、学習すると完全に受け入れられ、プラグインもかなり良いです。しかし、私は個人的に自分のものをコーディングする手が長期的にははるかに優れたアプリケーションになると感じています。プラスそれはより楽しいです;) – zilj