How can I get the value of the checked radio button when submitting a form using angularjs?

前端 未结 4 747
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 11:37

I have a few forms. Each form have a few possible radio buttons and a submit button. Only one radio button can be checked (using the same name attribute for each radio). How

4条回答
  •  一个人的身影
    2020-12-06 12:05

    Your radio button's value will be available on whatever scope property you've assigned ng-model="" to on the input element. Try something like this:

    JS

    app.controller('MyCtrl', function($scope){ 
       $scope.submitForm = function (){
           alert($scope.radioValue):
       };
    
       $scope.radioValue = 1;
    });
    

    HTML

    currently selected: {{radioValue}}

    And, so you can see it working, here is a plunker demonstrating the example

提交回复
热议问题