Angularjs 如何在angular js中为ng show添加超时?
我正在开发测验应用程序。我已经为每个问题添加了超时,即使用户是否尝试该问题 查看我的代码:Angularjs 如何在angular js中为ng show添加超时?,angularjs,timeout,ng-show,Angularjs,Timeout,Ng Show,我正在开发测验应用程序。我已经为每个问题添加了超时,即使用户是否尝试该问题 查看我的代码: <p ng-repeat="opt in question.answer"> <label ng-show="opt._correct" for=""> <input type="radio" name="questionAnswer" id="opt.id" value="" ng-click="checkAnswer(1)"
<p ng-repeat="opt in question.answer">
<label ng-show="opt._correct" for="">
<input type="radio" name="questionAnswer" id="opt.id" value=""
ng-click="checkAnswer(1)" />
{{opt.__text}}
</label>
<label ng-hide="opt._correct" for="">
<input type="radio" name="questionAnswer" id="opt.id" value=""
ng-click="checkAnswer(0)" />
{{opt}}
</label>
</p>
{{opt.}
{{opt}}
控制器中的我的代码:
$scope.randomQuestions = function(questionslist){
$scope.randomQuestion = questionslist
[Math.floor(Math.random() * questionslist.
length)];
console.log($scope.quiz);
var item = $scope.quiz.splice($scope.randomQuestion,1)[0];
$scope.questions = new Array();
$scope.questions.push($scope.randomQuestion);
$scope.counter = $scope.counter + 1;
return $scope.questions;
}
$scope.checkAnswer = function(option){
console.log('check answer');
if(option == 1){
console.log($scope.score);
$scope.score = $scope.score + parseInt($scope.level._points_per_question);
console.log($scope.score);
} else{
}
console.log($scope.counter);
if ($scope.counter < parseInt($scope.level._total_questions + 1)){
$scope.randomQuestions($scope.quiz);
} else {
console.log('5 questions');
}
}
$scope.nextLevel = function(){
$scope.total_score = $scope.total_score + $scope.score;
$scope.score = 0;
$scope.counter = 0;
if($scope.level_count == 1){
$scope.level_count = $scope.level_count + 1;
$scope.quiz = $scope.quiz2.question;
$scope.level = $scope.quiz2;
$scope.randomQuestions($scope.quiz);
} else if($scope.level_count == 2){
$scope.quiz = $scope.quiz3.question;
$scope.level = $scope.quiz3;
$scope.randomQuestions($scope.quiz);
$scope.level_count = $scope.level_count + 1;
} else {
$scope.level_count = $scope.level_count + 1;
$scope.result_text();
}
}
$scope.result_text = function(){
$scope.result = parseInt(($scope.total_score * 100) / 400);
for(var k=0; k < $scope.score_rules.length; k++){
if($scope.result >= $scope.score_rules[k]._min_percent){
$scope.score_status = $scope.score_rules[k].__text;
console.log($scope.score_rules[k].__text);
console.log($scope.score_rules[k]);
}
}
}
$scope.randomQuestions=函数(问题列表){
$scope.randomQuestion=问题列表
[Math.floor(Math.random()*问题列表。
长度];
log($scope.quick);
var item=$scope.quick.splice($scope.randomQuestion,1)[0];
$scope.questions=新数组();
$scope.questions.push($scope.randomQuestion);
$scope.counter=$scope.counter+1;
返回$scope.questions;
}
$scope.checkAnswer=函数(选项){
console.log(“检查答案”);
如果(选项==1){
log($scope.score);
$scope.score=$scope.score+parseInt($scope.level.\u每个问题的分数);
log($scope.score);
}否则{
}
console.log($scope.counter);
if($scope.counter=$scope.score\u规则[k]。\u最小值\u百分比){
$scope.score\u status=$scope.score\u规则[k]。\u文本;
log($scope.score\u rules[k]。\u text);
console.log($scope.score_rules[k]);
}
}
}
有人能建议如何从视图中调用超时吗?您可以使用CSS转换或动画来执行实际转换,并使用来触发转换
有几个示例可用于
ngAnimate
on.您可以使用CSS转换或动画来执行实际转换,并使用来触发转换
上的
ngAnimate
有几个示例。请在下面的代码中找到
function controller($scope)
{
$scope.showflag = true;
setTimeout(function ()
{
$scope.$apply(function()
{
$scope.showflag = false;
});
}, 1000);
}
请找到下面的代码
function controller($scope)
{
$scope.showflag = true;
setTimeout(function ()
{
$scope.$apply(function()
{
$scope.showflag = false;
});
}, 1000);
}
您可以尝试以下方法:
- 修改
代码并调用另一个设置 超时/睡眠。当调用从超时函数返回时,设置 变量(例如,checkAnswer()
)设置为isVisible
,并在false
中使用此变量。 大概是这样的:ng show
- 因此,新的
看起来像ng show
ng show=“isVisible&&opt.\u correct”
- 修改
代码并调用另一个设置 超时/睡眠。当调用从超时函数返回时,设置 变量(例如,checkAnswer()
)设置为isVisible
,并在false
中使用此变量。 大概是这样的:ng show
- 因此,新的
看起来像ng show
ng show=“isVisible&&opt.\u correct”