【发布时间】:2013-07-25 23:28:06
【问题描述】:
我在表单中使用无线电输入,我在它们两个上都输入了相同的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
}
}]);
【问题讨论】:
标签: ruby-on-rails angularjs radio-button