1.0.1-beta • Published 1 year ago

ngx-quiz v1.0.1-beta

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

Installing

npm install ngx-quiz

Usage

Import NgxQuizModule

import {NgxQuizModule} from 'ngx-quiz';

@NgModule({
  imports: [
    NgxQuizModule
  ]
})

Usage

Use it in your template and then pass a Quiz object to the component as follows as an example

<ngx-quiz [quiz]="quiz"></ngx-quiz>

Configuration

Quiz

PropertyTypeDescription
namestringThe quiz name, if defined, will appear on the start and end screen
levelstringThe quiz level, if defined, will appear on the start and end screen
durationnumberThe quiz duration in ms, if defined, will appear on the start and end screen
automaticAdvancebooleanAllows you to advance the question automatically after being answered
returnAllowedbooleanAllows the user to return to the previous question
repeatAllowedbooleanAllows the user to repeat the test when finished
emitReportbooleanIf set to true, the quiz will emit a report with the user's choices when finished
startScreenStartScreenConfigure the intro screen. If omitted it will not be displayed
endScreenEndScreenConfigure the end screen. If omitted, default values will be used
questionsQuestion[]An array with the quiz questions

Question

PropertyTypeDescription
typeQuestionTypeType of question, for now only 'single' applies
titlestringTitle of question
descriptionstringDescription of question (optional)
displayImagestringAn url image to display in the question
answersSingleAnswerList of possible answers

SingleAnswer

PropertyTypeDescription
displayImagestringAn url image to display in the answer
displayTextstringAnswer display text
valuenumberValue of the answer (this computes for the final score

StartScreen & End Screen

PropertyTypeDescriptionDefault (Only in end screen)
titlestringTitle to show on the screen"Congrats!"
descriptionstringDescription to show on the screen"You just completed"
displayImagestringUrl image to show on the screen
buttonTextstringText to display on the button"Restart"

Quiz object example

const quiz: Quiz = {
    name: 'Angular',
    level: 'Beginner',
    duration: 480,
    automaticAdvance: false,
    returnAllowed: true,
    repeatAllowed: true,
    emitReport: true,
    startScreen: {
      title: '',
      description: '',
      displayImage:
        'https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Angular_full_color_logo.svg/1200px-Angular_full_color_logo.svg.png',
      buttonText: 'Start'
    },
    endScreen: {
      title: '¡Congratulations!',
      description: 'You complete the quiz!',
      displayImage:
        'https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Angular_full_color_logo.svg/1200px-Angular_full_color_logo.svg.png',
      buttonText: 'Restart'
    },
    questions: [
      {
        type: 'single',
        title: 'In Angular, you can pass data from the parent component to the child component by using:',
        description: 'Choose the correct answer',
        displayImage: 'https://cdn.searchenginejournal.com/wp-content/uploads/2019/04/the-seo-guide-to-angular-1520x800.png',
        answers: [
          { displayText: '@Output()', value: 100 },
          { displayText: '@Input()', value: 0 },
          { displayText: 'Output', value: 0 },
          { displayText: 'Input', value: 0 }
        ]
      },
      {
        type: 'single',
        title: 'Which directive connects the value of the controls to the data?',
        description: 'Choose the correct answer',
        displayImage: 'https://cdn.searchenginejournal.com/wp-content/uploads/2019/04/the-seo-guide-to-angular-1520x800.png',
        answers: [
          { displayText: 'ng-app', value: 0 },
          { displayText: 'ng-init', value: 0 },
          { displayText: 'ng-model', value: 100 },
          { displayText: 'ng data', value: 0 }
        ]
      },
      {
        type: 'single',
        title: 'In Angular routing, which tag is used to render matched component via active route?',
        description: 'Choose the correct answer',
        displayImage: 'https://cdn.searchenginejournal.com/wp-content/uploads/2019/04/the-seo-guide-to-angular-1520x800.png',
        answers: [
          { displayText: '<router></router>', value: 0 },
          { displayText: '<router-output></router-output>', value: 0 },
          { displayText: '<router-outlet></router-outlet>', value: 100 },
          { displayText: '<router-display></router-display>', value: 0 }
        ]
      }
    ]
  };