Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
i have this html
HTML
<ul>
       <li data-ng-repeat="q in QuizObj">
           <fieldset><legend>All Quizes </legend>
           <h1>{{q.Quiz  }}</h1>
           <h3>options</h3>
           <h3>answer</h3>
               <input type="radio" />{{q.options[1]}}
               <input type="radio" />{{q.options[2]}}
               <input type="radio" />{{q.options[3]}}
               <input type="radio" />{{q.options[4]}}
           <h4>Answer</h4>
               <input type="radio" />{{q.answer}}

           </fieldset>
       </li>
   </ul>
<input type="text" ng-model="ans">
   <input type="text" ng-model="Question" >

   <input type="text" ng-model="type">
   <input type="button" data-ng-click="addQuiz()">

and this is js angular code
JavaScript
angular.module('quizApp',[])
.controller('mainCtrl',function($scope,crudService){

$scope.name="this";
        alert(JSON.stringify(crudService.quiz));
        $scope.QuizObj= crudService.quiz;
    })
    .service('crudService',function(){
        this.quiz=[
            {
                Quiz: "what is the C#",
                options: {  1: 'P-lang',
                            2:'h-lang',
                            3: 'A-lang',
                            4: 'nothing'
                        },
                type: 'radio',
                answer: 1
            },
            {
                Quiz: "what is the J#",
                options: {  1: 'P-lang',
                    2:'h-lang',
                    3: 'A-lang',
                    4: 'nothing'
                },
                type: 'radio',
                answer: 1
            },
            {
                Quiz: "what is the VB",
                options: {  1: 'PL',
                    2:'hL',
                    3: 'AL',
                    4: 'nothing'
                },
                type: 'radio',
                answer: 1
            }
        ]

    })


i have a some problem

i want to add question into quiz while quiz object is in service how to add this i am doing
this
JavaScript
$scope.addQuiz= function($scope){
           crudService.quiz.push({
               Quiz: $scope.Question,
               type: $scope.type,
               answer: $scope.ans
           })

       }

but showing me an error
TypeError: Cannot read property 'Question' of undefined
how to push in services's object (quiz). ??
how to push in option which is another object in Quiz object. ??
plus i want to allow user to add type of answer
types are
1: true\false (checkbox)
2: Mulitiple answer (checkbox)
3. single answer (radio)
how to do this ?? although i have added a opition in quiz but don't know how to do this and create its layout??
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900