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

前端 未结 2 1313
不知归路
不知归路 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条回答
  • 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: <input type="text" ng-model="person.first" />
    Last: <input type="text" ng-model="person.last" />
    <button ng:click="save()">Save</button>
    

    JavaScript - controller

    function FormCntl($scope, $http) {
      $scope.save = function() {
        $http.put('/save.py', $scope.person);
      };
    }
    
    0 讨论(0)
  • 2021-02-02 01:15

    As far as I know, there isn't really a good way to modify headers which angular sends to server expect for editing angular source. This is planned enhancement, but it's still not done.

    I think that angular google group might be better place to ask specific questions like this since developers are really friendly and knowledgeable.

    0 讨论(0)
提交回复
热议问题