Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = angular.module('QuizApp', [])
- app.controller('QuizCtrl', ['$http', function ($http) {
- this.answered = false;
- this.title = "loading question...";
- this.options = [];
- this.correctAnswer = false;
- this.working = false;
- this.answer = function () {
- return this.correctAnswer ? 'correct' : 'incorrect';
- };
- // GET
- this.nextQuestion = function () {
- this.working = true;
- this.answered = false;
- this.title = "loading question...";
- this.options = [];
- $http.get('/api/trivia').success(function (data, status, headers, config) {
- this.options = data.options;
- this.title = data.title;
- this.answered = false;
- this.working = false;
- }).error(function (data, status, headers, config) {
- this.title = "Oops... something went wrong.";
- this.working = false;
- });
- };
- // POST
- this.sendAnswer = function (option) {
- this.working = true;
- this.answered = true;
- $http.post('/api/trivia', { 'questionId': option.questionId, 'optionId': option.id }).success(function (data, status, headers, config) {
- this.correctAnswer = (data === "true");
- this.working = false;
- }).error(function (data, status, headers, config) {
- this.title = "Oops... something went wrong.";
- this.working = false;
- });
- };
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement