Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法获取单选按钮的角度值_Javascript_Angularjs - Fatal编程技术网

Javascript 无法获取单选按钮的角度值

Javascript 无法获取单选按钮的角度值,javascript,angularjs,Javascript,Angularjs,我有这些单选按钮,但我无法从提交的按钮中获得价值。我也试过同样的方法: HTML: <body ng-controller="ExamCtrl"> <form name="myForm" ng-submit="submitForm()"> <label><input type="radio" name="test" ng-model="radioValue" value="1"/> O

我有这些单选按钮,但我无法从提交的按钮中获得价值。我也试过同样的方法:

HTML:

        <body ng-controller="ExamCtrl">
           <form name="myForm" ng-submit="submitForm()">
             <label><input type="radio" name="test" ng-model="radioValue" value="1"/> One</label>
             <label><input type="radio" name="test" ng-model="radioValue" value="2"/> Two</label>
             <label><input type="radio" name="test" ng-model="radioValue" value="3"/> Three</label>
             <div>currently selected: {{radioValue}}</div>
             <button type="submit">Submit</button>
           </form>
        </body>

它记录“提交”,然后
未定义

当我使用点“.”符号时,它工作。不知道为什么

HTML


当我使用点“.”符号时,它起作用。不知道为什么

HTML


您的代码运行正常:

小提琴:

var myApp=angular.module('myApp',[]);
myApp.controller('MyCtrl',函数($scope){
$scope.submitForm=函数(){
console.log(“提交”);
console.log($scope.radioValue);
};
});

一个
两个
三
当前选定:{{radioValue}}
提交

您的代码工作正常:

小提琴:

var myApp=angular.module('myApp',[]);
myApp.controller('MyCtrl',函数($scope){
$scope.submitForm=函数(){
console.log(“提交”);
console.log($scope.radioValue);
};
});

一个
两个
三
当前选定:{{radioValue}}
提交

您是否尝试过plnkr???您应该初始化
$scope.radioValue在控制器的开始处。@NiRmaL然后它只记录初始化的值。您是否在HTML代码段中记录了类似的值,它是否显示了不同的值?当您选择其他单选按钮时。@NiRmaL在HTML中,表达式
{{radioValue}
会更改并显示单击的值。您是否尝试了plnkr???您应该初始化
$scope.radioValue在控制器的开始处。@NiRmaL然后它只记录初始化的值。您是否在HTML代码段中记录了类似的值,它是否显示了不同的值?当您在HTML中选择不同的单选按钮时,@NiRmaL,表达式
{{radioValue}}
会更改并显示单击的值。
   $scope.submitForm = function () {
       console.log('Submitting');
       console.log($scope.radioValue);
   };
<body ng-controller="ExamCtrl">
   <form name="myForm">
     <label><input type="radio" name="test" ng-model="radio.value" value="1"/> One</label>
     <label><input type="radio" name="test" ng-model="radio.value" value="2"/> Two</label>
     <label><input type="radio" name="test" ng-model="radio.alue" value="3"/> Three</label>
     <div>currently selected: {{radioValue}}</div>
     <button ng-click="submitAnswer(radio.value)">Submit</button>
   </form>
</body>
$scope.submitAnswer = function (selected) {
  // $scope.answer = 'A';
  console.log('submitting');        
  console.log(selected);
};