title: Angular bad data while trying to post http
body: <p>I try to send some data (from a form) via <code>$http</code> to my backend. But I'm getting <code>$http:baddata</code> error when I try to send the data. 
  The full error is "Data must be a valid JSON object" but in my opinion, it is a valid object!</p>
  
  <blockquote>
    <p><a href="https://docs.angularjs.org/error/" rel="nofollow noreferrer">https://docs.angularjs.org/error/</a>$http/baddata?p0=%3Cbr%20%2F%3E%0A%3Cb%3ENotice%3C%2Fb%3E:%20%20Undefined%20index:%20formData%20in%20%3Cb%3EC:%5Cxampp%5Chtdocs%5Cuno-form%5Capi%5Ccontrollers%5CFormController.php%3C%2Fb%3E%20on%20line%20%3Cb%3E26%3C%2Fb%3E%3Cbr%20%2F%3E%0A%7B%22success%22:true,%22data%22:%7B%22form%22:null%7D%7D&amp;p1=%7B%7D</p>
  </blockquote>
  
  <p>This is the code, and the <code>console.log()</code> result</p>
  
  <pre><code>$scope.submitForm = function(){
          console.log("submitForm");
          console.log($scope.formData, angular.toJson($scope.formData));    
  
          var data = {
              formData: angular.toJson($scope.formData)
          }
          var config = {
              headers : {
                  'Content-Type': 'application/json'
              }
          }
  
          $http.post('/api/save-form', data,config)
          .then(function(response){
              console.log("RESPONSE", response);
          },function(reason){
              console.log("Err");
              console.error(reason);
          })
      }
  </code></pre>
  
  <p>Console.log:</p>
  
  <pre><code>submitForm
  home.controller.js:47 {firstName: "Test"} "{"firstName":"Test"}"
  home.controller.js:63 Err
  home.controller.js:64 Error: [$http:baddata] (...)
  </code></pre>
  
  <p>Model in frontend (<pre>{{formData}}</pre>)</p>
  
  <pre><code>{
    "firstName": "Test"
  }
  </code></pre>
  
  <p>I have some other way's to send the data, without config, with the other $http way <code>($http({method: 'POST',....})</code> but no luck.</p>
  
  <p>What I'm doing wrong here? I have created many forms and functions like this, but I never get this error...</p>