Forms 如何以老式方式提交AngularJS模型?
在我的Angular应用程序中,我有一个绑定到模型的表单。表单没有用于所有模型属性的字段。 当用户点击submit按钮时,我希望以传统方式发布表单,而不是AJAX请求(我必须处理已经存在的服务器端脚本) 如果我在表单中添加一个Forms 如何以老式方式提交AngularJS模型?,forms,angularjs,Forms,Angularjs,在我的Angular应用程序中,我有一个绑定到模型的表单。表单没有用于所有模型属性的字段。 当用户点击submit按钮时,我希望以传统方式发布表单,而不是AJAX请求(我必须处理已经存在的服务器端脚本) 如果我在表单中添加一个操作,这基本上是可行的。但是,它显然只按原样提交带有当前字段的表单,而不是像使用$http服务时那样提交整个模型。 此外,它不创建名称属性 我怎样才能以传统的方式提交包含完整模型数据的表格?我是否必须自己创建缺少的表单字段,或者是否有办法让Angular为我创建表单字段 &
操作
,这基本上是可行的。但是,它显然只按原样提交带有当前字段的表单,而不是像使用$http
服务时那样提交整个模型。
此外,它不创建名称属性
我怎样才能以传统的方式提交包含完整模型数据的表格?我是否必须自己创建缺少的表单字段,或者是否有办法让Angular为我创建表单字段
<script>
angular.module('foobar', []).controller('ContentCtrl', ['$scope', function($scope) {
$scope.content = {
'title': 'Foo',
'subtitle': 'Bar',
'text': 'desc' // this field is missing in the form itself and therefore is not submitted
};
}]);
</script>
<form action="http://postcatcher.in/catchers/521c6510429f840200000169" method="post" ng-controller="ContentCtrl">
<input type="text" name="est" ng-model="content.title" value="asdf">
<input type="text" ng-model="content.subtitle">
<button>submit</button>
<a href="http://postcatcher.in/catchers/521c6510429f840200000169">see post result</a>
</form>
角度.module('foobar',[]).controller('ContentCtrl',['$scope',function($scope){
$scope.content={
“title”:“Foo”,
'副标题':'酒吧',
'text':'desc'//表单本身缺少此字段,因此未提交
};
}]);
提交
这里有一个例子:当您有一个定义了动作的表单时,Angular不会做任何特殊的事情。这是一个纯粹的html表单提交,包含定义的字段 通常,您会使用:
<input type="hidden" ng-model="content.desc">
但是angular仍然不支持绑定到隐藏的输入
解决办法是:
<input type="text" name="text" ng-model="content.text" ng-hide="true">
但这意味着,我必须自己创建字段?很遗憾,是的:)。谢谢!但不是很令人满意。