2

I want to make Multiple-choice test with ionic for android

Where I save Questions and how show the Questions?

How understand user selects the right answer?

Can you please help me.

sadegh
  • 1,720
  • 1
  • 16
  • 30
maryam p
  • 69
  • 12

2 Answers2

1

you should save the questions in the controller associated with the route and view you would like to present the questions from. this would be in the controllers.js file from either quickstart.

the easiest way to tell if the user selects the right answer might be to put an ng-click attribute on each answer which calls a function in your controller which determines whether the selected answer is correct or not.

you should start by doing some angularjs tutorials, because that is what an ionic application is based on.

good luck.

ekill
  • 176
  • 7
  • Thank you,how i can save the questions in the controller associated?! can you please send a tutorials link about this or give me more details – maryam p Jul 25 '15 at 04:39
  • 1
    @maryamp i might suggest starting here http://learn-angular.org/ if you used ionic start myApp tabs or ionic start myApp sidemenu, you should have this file in your project www/js/controllers.js. there will be one controller per view of the ionic application. You will want to pick a view and create a variable like this $scope.questions = ["Question 1","Question 2"] etc you will really need to learn angularjs, the ui-router and some things about ionic to build your app. you will need to know html / css and js pretty well first. – ekill Jul 25 '15 at 04:57
1

you can save Questions to json format and then you can get Questions from json file

for more information use this links

» http://learn.ionicframework.com/formulas/backend-data/

» AngularJS: factory $http.get JSON file

» https://www.phase2technology.com/caching-json-arrays-using-cachefactory-in-angularjs-1-2-x/


for example

this is my Questions file with JSON format

{

    "Questions": [


        {

            "QuestionsID" : "1", 
            "QuestionsTitle" : "question 1",
            "QuestionsText" : "which one is Answers?",
            "Answers1" : "i'm Answers",
            "Answers2" : "i'm not Answers",
            "Answers3" : "i'm not Answers",
            "Answers4" : "i'm not Answers",
            "TrueAnswers" : "Answers1"
        },


        {

            "QuestionsID" : "2", 
            "QuestionsTitle" : "question 2",
            "QuestionsText" : "which one is Answers?",
            "Answers1" : "i'm not Answers",
            "Answers2" : "i'm Answers",
            "Answers3" : "i'm not Answers",
            "Answers4" : "i'm not Answers",
            "TrueAnswers" : "Answers2"
        }

    ]

}

Now i can get Questions from json file and save in arrays then use this array

this is angular code

// Caching the river...
myApp.factory('myCache', function($cacheFactory) {
 return $cacheFactory('myData');
});

// Displays a list of articles in the river
myApp.controller('MyMain', ['$scope', '$http', 'myCache',
 function ($scope, $http, myCache) {
   var cache = myCache.get('myData');
   if (cache) {
     $scope.variable = cache;
   }
   else {
     $http.get('lib/Questions.son')
       .success(function(data) {
         $scope.variable = data;

         myCache.put('myData', data);
       }
    );
  }
}

Now can use $scope.variable

Your question is too general,I think it is better go this link and learn AngularJS https://www.codecademy.com/en/courses/learn-angularjs

Community
  • 1
  • 1
sadegh
  • 1,720
  • 1
  • 16
  • 30
  • you can save true answer with each question and check user select true answer – sadegh Jul 25 '15 at 04:48
  • 1
    you can use this tutorials this is good for you [Caching JSON Arrays](https://www.phase2technology.com/caching-json-arrays-using-cachefactory-in-angularjs-1-2-x/) – sadegh Jul 25 '15 at 04:48