0

What is the recommended way to submit a form with angularjs. Will all the different form fields be automatically turned into JSON?

Tom
  • 7,640
  • 1
  • 23
  • 47
alexl
  • 1,842
  • 1
  • 14
  • 15
  • [Angular Best Practices](http://stackoverflow.com/q/20802798/1959948) – Dalorzo Aug 31 '14 at 01:22
  • -1 already? I don't see why you guys have to try to make technology inaccessible to lay people, unless you realize your job is so easy that you have to protect it through artificial means. – alexl Aug 31 '14 at 01:23

1 Answers1

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>
alexl
  • 1,842
  • 1
  • 14
  • 15