AngularJS - How do I submit a form to a controller on the server?

前端 未结 2 1352
不知归路
不知归路 2021-02-02 00:20

The cookbook form examples on the AngularJS site only save the state on the client. How do I submit to the server?

Alternatively, how do I use jQuery\'s form.submi

2条回答
  •  不要未来只要你来
    2021-02-02 00:54

    Note, there is strict separation of view (your html template) and logic (your JS code) - mainly because of testability.

    The right way is to just send your model to the server, using $resource (for REST) or low level $http. Instead of doing the job in the template.

    Simple example - HTML template

    First: 
    Last: 
    
    

    JavaScript - controller

    function FormCntl($scope, $http) {
      $scope.save = function() {
        $http.put('/save.py', $scope.person);
      };
    }
    

提交回复
热议问题