验证是否在提交的页面中选中单选按钮:AngularJs

时间:2014-05-26 11:05:46

标签: javascript angularjs

我是AngularJS的新手。我用工厂的一些问题用dou p the dom。我必须验证是否选中了单选按钮。请给出建议以改进此代码

的index.html

<body ng-app="quiz">
    <div id="container" ng-controller="QuizController"> 
        <button ng-click="submitfun()">submit</button>
    </div>  
</body>

app.js

angular.module('quiz', ['quiz.service','quiz.directive']);

var QuizController = function($scope, questionFactory) {
    $scope.questions_and_answers = questionFactory;
    $scope.checkList=[];    
    $scope.submitfun= function(message){
        alert('hi');         
    }   
};

factory.js

angular.module('quiz.service', [])
    .factory('questionFactory', function() {
        return [
            { question: "Which of these is England's official slogan for the World Cup?", answerChoices: [ "Impossible is not an English word", "One nation, one team, one dream!", "Real men wear red and white","The dream of one team, the heartbeat of millions!!" ] },
            { question:"Who was Roy Keane talking this week about when he said: \"Not everybody wants to wander around the pitch waving and crying?\" ", answerChoices:["David Moyes","John Terry","Luis Suárez","Rio Ferdinand"]}
        ];
});

1 个答案:

答案 0 :(得分:2)

您可以使用ng-disabled和ng-show指令的组合进行验证并显示错误消息。

请参阅此plnkr