簡體   English   中英

驗證是否在提交頁面上選中了單選按鈕:AngularJs

[英]Validate if radio buttons are checked in a page on submit: 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM