我有一個名爲instructions.html的HTML頁面。當我點擊這個頁面上的按鈕時,它應該通過測驗list.html並打開一個「開始測驗」按鈕打開對話框。當我點擊這個按鈕時,彈出窗口會消失並開始測驗。但點擊按鈕沒有發生。點擊ng對話框中的按鈕不起作用
下面是instructions.html頁面。
<div class="container-fluid" ng-controller="KbcQuizController">
<div class="instructions-container">
<div class="instructions-heading">
<span class="header-text"> Rules </span>
</div>
<div>
<p>1. Persons must enter the Competition on their own behalf and
entry(ies) by proxy will not be accepted, even for their family
members.</p>
<p>2. An entry/ies is not transferrable.</p>
<p>3. The Company or the Producers will not entertain any claims
/questions/queries with respect to the authenticity or
correctness of any questions and answers for the questions asked in
any round of the Competition.</p>
<p>4. The Company’s decision on the correctness or incorrectness
of any answer is final and binding on all Contestants.</p>
<p>5. Use of mobile phones will not be permitted during the
shoot, and during the Auditions. It may lead to disqualification.</p>
</div>
<div class="next-container">
<button class="next-button btn btn-primary" ng-click="getWelcomePage()">Start Quiz</button>
</div>
</div>
</div>
這裏是我的控制器:
(function() {
'use strict';
angular.module('app.kbcquiz').controller('KbcQuizController',KbcQuizController);
KbcQuizController.$inject = [ '$timeout', '$rootScope', '$scope', '$http','$filter', 'ngDialog', 'usSpinnerService', 'quizService', '$state' ];
function KbcQuizController($timeout, $rootScope, $scope, $http, $filter,ngDialog, usSpinnerService, quizService, $state) {
console.log("quizService is::" + quizService);
$scope.count = 1;
$scope.timer = {
value : 60
}
var stopped;
$scope.startTimer = function() {
stopped = $timeout(function() {
console.log($scope.timer.value);
$scope.timer.value--;
$scope.startTimer();
if ($scope.timer.value == 0) {
alert("timeout");
}
}, 1000);
};
$scope.stop = function() {
$timeout.cancel(stopped);
}
$scope.reset = function() {
$scope.timer.value = 60;
}
$scope.startQuiz = function() {
console.log("in start quiz");
quizService.getQuestion($scope.count).then(null, function(err) {
console.log("error in get question");
});
$scope.startTimer();
}
$scope.getWelcomePage = function() {
$state.go('quizpage');
ngDialog
.open({
template : 'app/modules/kbcquiz/welcome.html',
className : 'ngdialog-theme-default',
controller : KbcQuizController,
controllerAs : 'vm',
scope : $scope,
});
}
}
})();
這裏是我的模塊:
(function() {
'use strict';
var module = angular.module('app.kbcquiz', [ 'ui.router','angularUtils.directives.dirPagination', 'ng-bootstrap-datepicker','ngDialog', 'angularSpinner' ]);
module.config(appConfig);
appConfig.$inject = [ '$stateProvider' ];
function appConfig($stateProvider) {
$stateProvider.state('app.kbcquiz', {
url : '/rules',
templateUrl : 'app/modules/kbcquiz/instructions.html',
})
.state('quizpage', {
url : '/app/kbc-quiz',
templateUrl : 'app/modules/kbcquiz/quiz-list.html',
});
}
})();
這裏是我的welcome.html:
<h3 class="dialog_header">Welcome to KBC!!</h3>
<div class="dialog-contents" ng-controller="KbcQuizController">
<div class="ngdialog-message">
<div>
<div class="next-button">
<button type="submit"
class="ngdialog-button ngdialog-button-primary"
ng-click="startQuiz(); closeThisDialog('button')">Start Quiz</button>
</div>
</div>
</div>
</div>
請讓我知道我錯了。因爲當我點擊ng對話框中的按鈕時,它甚至不會啓動startQuiz()方法。
謝謝。它現在工作:) – Arnav