提交带有角度js的表单的推荐方法是什么

时间:2014-08-31 01:16:51

标签: angularjs

使用angularjs提交表单的推荐方法是什么?是否所有不同的表单字段都会自动转换为JSON?

1 个答案:

答案 0 :(得分:0)

<DOCTYPE html>
<html>
<head></head>
<body>
<div ng-app='mymodule' ng-controller="PeopleController as pc">
<form name="myform" ng-submit="pc.submit(person)">
<input  ng-model="person.name"/>
<input  ng-model="person.age"/>
<input type="submit" />
</form>
</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular.min.js"></script>
<script>
(function (){
 angular.module('mymodule',[])
 .controller('PeopleController',function($scope,$http) {
   $scope.person={'name':'john'};
   this.submit = function(p){$http.post('/path/to/my.php',p).success(function(e){console.log(e);});};
 });
})();
</script>
</body>
</html>