Javascript 选择中的ng模型不使用ng提交

Javascript 选择中的ng模型不使用ng提交,javascript,angularjs,Javascript,Angularjs,代码如下: HTML 这是输出: undefined hello 当我检查源代码时,附加到select的选项如下所示: <option label="x" value="undefined:undefined"></option> 如何在ng submit上获取控制器中的所选选项?检查此项……当您更改数据时,我使用此项进行了更新 var-app=angular.module('plunker',[]); 应用程序控制器('MainCtrl',函数($scope)

代码如下:

HTML

这是输出:

undefined
hello
当我检查源代码时,附加到select的选项如下所示:

<option label="x" value="undefined:undefined"></option>


如何在ng submit上获取控制器中的所选选项?

检查此项……当您更改数据时,我使用此项进行了更新

var-app=angular.module('plunker',[]);
应用程序控制器('MainCtrl',函数($scope){
$scope.tables=[{“id”:1,“name”:“x”},{“id”:2,“name”:“y”},{“id”:3,“name”:“z”}];
$scope.fun=函数(){
console.log($scope.a);
console.log($scope.b);
}
});

安古拉斯普朗克
文件。写(“”);
你好{{name}}


由于您正在访问
ng选项中的
table.id
table.name
,因此需要将数组更改为如下所示的对象数组

$scope.tables = [{"id":"1","name":"1"},{"id":"2","name":"2"},{"id":"3","name":"3"}];
角度模块(“应用程序”,[]) .controller(“ctrl”,函数($scope){ $scope.tables=[{“id”:“1”,“name”:“1”},{“id”:“2”,“name”:“2”},{“id”:“3”,“name”:“3”}]; $scope.fun=函数(){ console.log($scope.a); console.log($scope.b); } })

好啊

provide tables Data您没有为select添加任何选项。呈现HTML时,您可以在下拉列表中看到哪些选项?我添加了tables数组。选项正确显示在选择框中。您必须在模型中为selec设置默认值。这可能会有所帮助:更改了阵列,但仍在打印undefined@PiyushShrivastava您能否在输出选项的值字段中创建PLNKR,它显示为:x,但我的选项如下:x检查此plunker并与您的Hanks进行比较,发现bugIt在我的对象数组格式中。这有点像
{“values”:{“id”:1….
I缺少
values
键。
<option label="x" value="undefined:undefined"></option>
$scope.tables = [{"id":"1","name":"1"},{"id":"2","name":"2"},{"id":"3","name":"3"}];