84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
本人更改公司一个项目,将JQuery中的$.ajax更改成AngularJS中的$http,原来提交数据的时候是$("#form").serialize(),而现在提交数据需要将数据一个个列出来封装成json提交,这里就是想问,angularjs中有没有方法可以向前者一样,一次性将全部的表单数据提交。(PS:公司要求项目中不要再用JQuery)
人生最曼妙的风景,竟是内心的淡定与从容!
<input ng-model="user.name"> <input ng-model="user.age">
Get the object by naming it ng-model在controller中直接使用$scope.user as above.
ng-model
controller
$scope.user
Specify the name attribute for the form element, and then the form will define a form controller with this name in the scope where it is located.
For example
<form name="myForm"> <input name="myInput"> </form>
Then use the following operations to get the value
function getFormValue(formCtrl) { return Object .keys(formCtrl) .filter(function(key) { return key[0] != '$'; } .reduce(function(res, key) { res[key] = formCtrl[key].$modelValue; return res; }, {}); } getFormValue($scope.myForm); // output: {myInput: "..."}
Get the object by naming it
ng-model
在controller
中直接使用$scope.user
as above.Specify the name attribute for the form element, and then the form will define a form controller with this name in the scope where it is located.
For example
Then use the following operations to get the value