0

I am creating a hybrid quiz application with AngularJS. I have below pseudo code,

  • index.html where user selects the quiz.
  • 2nd page using ui-view Quiz is rendered and user selected options are stored in a global array (Should I use global here ?)
  • The values in array are compared with values in answer array (should answers array be global? This array is created by querying the database and on each new quiz this array has to change as this will select questions randomly.)
  • Will both the arrays be carried forward to the score view (when using them as local arrays or I need to to make them global or they will not be carried to next view?)

I am new to single page application and UI-Router so don't know how does it all work.

1 Answer 1

1

I don't think you should store user's selected options in Global variable because these aren't common variable to be used throughout the user session. You can save it in database when user redirects to 2nd page and retrieve on score view screen. Also, You may need this information in future to retain the user's records.

EDIT - In case you can not store data in database and storing data at client side is only option then local storage can be used.

Sign up to request clarification or add additional context in comments.

4 Comments

I only want to save the average score to the database as the quiz questions are randomly generated so storing user records for random quiz is a very difficult. Are you sure variables are not carried forward on next view in Agularjs. Here only views are changing and so I have doubt
My array will be of less than 1024 characters so should I use cookie to store these variables? I will unset the cookie on score page so I can use the same cookie name in other quiz
I did not say variables are not carried forward. If you can not store in DB and client side is only option, You can also use local storage to store the data.
local storage seems to be the best for my current requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.