我在一个表单中使用无线电输入,我ng-model
对它们都设置了相同的。但是我无法在我的控制器中获取值,但是我可以获取其他ng-model
字段的值。
你可以在jsfiddle和codepen上找到我的代码(由于某些原因,它们都没有工作)
这是haml形式
%form.project{'ng-submit' => "createNewProject()"}
.name
%input{'ng-model'=>'name', :type => :text, :placeholder => 'Name', :name => "name"}
.description
%textarea{'ng-model'=>'description', :placeholder => 'Description', :required=>true, :name => "description"}
.orientation
%input#portrait{'ng-model'=>'orientation', :type=>"radio", :name=>"orientation", :value=>"1", :checked=>true}
%label{:for=>"portrait"}
%input#landscape{'ng-model'=>'orientation', :type=>"radio", :name=>"orientation", :value=>"2"}
%label{:for=>"landscape"}
这是控制器
app.controller('theController', ['$scope', function($scope)
{
$scope.createNewProject = function()
{
var item = {
name:this.name,
description:this.description,
orientation:this.orientation
};
//item.orientation is undefined
}
}]);