title: How do I send form data to server using angular?
body: <p>Currently, I am using a server side framework CakePHP to build my app.</p>
  
  <p>I need to integrate angular into my app.</p>
  
  <p>Currently, I send the following inputs </p>
  
  <p><code>User.old_password</code>, <code>User.new_password</code>, <code>User.new_password_confirm</code></p>
  
  <p>to this url <code>/mypasswords/new</code> using POST</p>
  
  <p>This works just fine.</p>
  
  <p>I understand that to send data to server side I need to use services in Angular.</p>
  
  <p>This is my Angular code so far.</p>
  
  <pre><code>var app = angular.module("myApp", []);
  
  app.controller('passwordController', ['$scope', function($scope) {
    $scope.submitted = false;
    $scope.changePasswordForm = function() {
      if ($scope.change_password_form.$valid) {
        // Submit as normal
      } else {
        $scope.change_password_form.submitted = true;
      }
    }
  }]);
  
  services = angular.module('myApp.services', ['ngResource']);
  
  services.factory("UserService", function($http, $q) {
    var service;
    // service code here
  });
  </code></pre>
  
  <p>So what do I write in the <code>//service code here</code> part? What other parts am I missing?</p>
  
  <p>My form currently looks like this as html after being rendered. (I know I probably have to remove action and method attributes from my form. Do I?)</p>
  
  <pre><code>&lt;form action="/mypasswords/new" id="change_password_form" name="change_password_form" ng-controller="passwordController" ng-submit="changePasswordForm()" method="post" accept-charset="utf-8" class="ng-scope ng-pristine ng-valid"&gt;
  
  &lt;div style="display:none;"&gt;&lt;input type="hidden" name="_method" value="POST"&gt;&lt;/div&gt;            
  
  &lt;input name="data[User][old_password]" id="u56" placeholder="Enter old password..." class="u56 profile_input" type="password"&gt;
  &lt;input name="data[User][new_password]" id="u57" placeholder="Enter new password..." class="u57 profile_input" type="password"&gt;
  &lt;input name="data[User][new_password_confirm]" id="u58" placeholder="Enter new password..." class="u58 profile_input" type="password"&gt;
  &lt;div id="u25" class="u25_container"&gt;
      &lt;div id="u25_img" class="clear_all_button detectCanvas" onclick="document.getElementById('change_password_form').reset()"&gt;
       &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div id="u27" class="u27_container"&gt;
      &lt;input id="u27_img" class="submit_button detectCanvas" type="submit" value="SAVE"&gt;                         
  
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Thank you.</p>