javascript - 验证提交时页面中是否选中单选按钮 : AngularJs

标签 javascript angularjs

我是 AngularJS 新手。我使用工厂向 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"]}
        ];
});

最佳答案

您可以结合使用 ng-disabled 和 ng-show 指令来验证和显示错误消息。

查看此plnkr

关于javascript - 验证提交时页面中是否选中单选按钮 : AngularJs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23868674/

相关文章:

javascript - 如果您不使用 var 声明全局变量或者它不是参数,为什么在某些情况下函数中的全局变量不会被更改?

javascript - 如何返回以下 _.map + Promise 函数?

angularjs - Angular $http.put REST

javascript - Angular/PHP 中的 Cookie?

javascript - 启用 CORS AngularJS 发送 HTTP POST 请求

javascript - 如何使用 javascript 或 angularjs 保存 json 文件?

javascript - 限制容器内可放置拖动项目的数量

javascript - 如果 div 向下移动,则不会触发按钮单击

javascript - 为什么 "ended"音频html5事件多次触发?

javascript - 使用 Casperjs 在 Angularjs 中单击