python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
Quiz questions in AngularJs

Quiz questions in AngularJs



The AngularJs code-sample

var app = angular.module('quizApp', []);
app.controller('quizCtrl', function($scope) {
    $scope.checkResult = function(item) {
    //check answers.
    };

    $scope.calRresult = function() {
    //calculat result.
    };

    $scope.quizAnsw = [{ ans: 'Igor Minar', correct: 0 }, { ans: 'Brad Green', correct: 0 },
        { ans: 'Misko Hevery', correct: 1 }, { ans: 'Steve Souders', correct: 0 }];
});

The full example code(HTML + AngularJs)

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Quiz questions in AngularJs</title>
    <link rel="stylesheet" href="style.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.min.js"></script>
    <script>
        var app = angular.module('quizApp', []);

        app.controller('quizCtrl', function ($scope) {
            $scope.checkResult = function (item) {
                //check answers.

                //if (item > 0) {
                // alert("Correct Answer!");
                //} else {
                ///  alert("Wrong Answer!");
                //}
            };

            $scope.calRresult = function () {
                //calculate result.
            };

            $scope.quizAnsw = [{ ans: 'Igor Minar', correct: 0 }, { ans: 'Brad Green', correct: 0 },
                { ans: 'Misko Hevery', correct: 1 }, { ans: 'Steve Souders', correct: 0 }];
        });
    </script>
</head>
<body ng-app="quizApp" ng-controller="quizCtrl">
    <div>
        <h4>Q1 : Who created AngularJs framework?</h4>
        <div ng-repeat="quiz in quizAnsw">
            <label ng-click="checkResult(quiz.correct)">
                <input type="radio" name="answ" ng-value="$index" ng-model="quizSelectedAns" /> {{quiz.ans}}
            </label>
        </div>
        <br>
        <input type="button" ng-click="calRresult()" value="Quiz Result" class="fb9" />
    </div>
</body>
</html>


Result : click for result http://embed.plnkr.co/B10yZ4/preview

ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions