AngularJS $http sending data with Ajax URL

i have used this code before i use angularjs.

function ajax_post(){
      // Create our XMLHttpRequest object
      var hr = new XMLHttpRequest();
      // Create some variables we need to send to our PHP file
      var url = "myUrl";
      var fn = document.getElementById("username").value;
      var ln = document.getElementById("password").value;
      var vars = "username="+fn+"&password="+ln;

      hr.open("POST", url, true);
      // Set content type header information for sending url encoded variables in the request
      hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      // Access the onreadystatechange event for the XMLHttpRequest object
      hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
          var return_data = hr.responseText;

        if(return_data=="1"){
          console.log("this is return data"+return_data);

        }else{

          ons.notification.alert({message: 'Login Failed!'});

        }

        }
      }
      // Send the data to PHP now... and wait for response to update the status div
      hr.send(vars); // Actually execute the request 
  }

Here with AngularJS to do same thing

$scope.ajaxLogin = function(){

    var fn = document.getElementById("username").value;
    var pw = document.getElementById("password").value;
     $http({
    url: "myURL", 
    method: "POST",
    data: { username: fn, password: pw },
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}

    }).success(function(data, status, headers, config) {
   // this callback will be called asynchronously
   // when the response is available

    if(status == 200) {
      var return_data = data;

    if(return_data == 0){
          console.log("test "+data,status);
          $scope.showAlertSucess();
        }else{

          $scope.showAlertError();
        }
      }
    }).
  error(function(data, status, headers, config) {
   // called asynchronously if an error occurs
   // or server returns response with an error status.
   $scope.showAlertNetwork();

    });

  };

but AngularJS way its not giving expected output which is "1" it gives "0". and i went through webconsole what i got is this part is different, i think it send data like JSON data: { username: fn, password: pw },
but my other code its not like that var vars = "username="+fn+"&password="+ln;

how to fix it to use with angularJS.

for more to understand here my PHP Code.

if ($result=mysqli_query($con,$sql))
  {

  $rowcount=mysqli_num_rows($result);
  printf($rowcount);

  mysqli_free_result($result);
  }

If you use AngularJs to provide variable in PHP use this code

$array = json_decode(file_get_contents('php://input'));

In $array input your variables.