AngularJS Http Post Method ($ with Parameters Example

Here we will learn what is http post method ($ in angularjs, uses of $ method in angularjs and how to use post method ($ with parameters in angularjs with example.

AngularJS Http Post ($ service

In angularjs we use $http service to send or get data from remote http servers using browsers XMLHttpRequest object. 


The $http.POST() services are used to send the data to a specific URL and expects the resource at that URL to handle the request that means we can say that  POST method is used to Insert new data based on given URL and it is one of the shortcut method in $http service.

Syntax of AngularJS $ Method

Following is the syntax of using $ method in angularjs applications.


var app = angular.module('putserviceApp', []);

app.controller('putserviceCtrl', function ($scope, $http) {

// Simple Post request example:

var url = 'posturl', data = 'parameters',config='contenttype';

$, data, config).then(function (response) {

// This function handles success

}, function (response) {

// this function handles error



If you observe syntax of angularjs $ method we have different properties like url, data, config and then success and error functions. We will learn each property in detail.


url We need to send url of http server to perform required operations.
data We will use this property to send required parameters to requested url.
config By using this property we can change content-type.

In above syntax, we passed $http as argument to the controller. To use service in controller we need to pass $http as parameter.


The response object which we will get after execution of $ method has following properties


  1. config  - The configuration object is used to generate the request.
  2. data - It’s either string or an object.
  3. headers - We can get header information.
  4. status - We can get HTTP status code of the response.
  5. statusText - Get HTTP status text of the response.

We will see how to use $ service in angularjs with example.

Example of AngularJS $ Service 

Following is the example of using angularjs $ service in application.


Live Preview

<!DOCTYPE html>




AngularJs $ Service Response Example


<script src=""></script>

<script type="text/javascript">

var app = angular.module('postserviceApp', []);

app.controller('postserviceCtrl', function ($scope, $http) {

$ = null;

$scope.age = null;

$scope.adress = null;

$scope.lblMsg = null;

$scope.postdata = function (name, age, adress) {

var data = {

name: name,

age: age,

adress: adress


//Call the services

$'/api/users/post', JSON.stringify(data)).then(function (response) {

if (

$scope.msg = "Post Data Submitted Successfully!";

}, function (response) {

$scope.msg = "Service not Exists";

$scope.statusval = response.status;

$scope.statustext = response.statusText;

$scope.headers = response.headers();







<div ng-app="postserviceApp" ng-controller="postserviceCtrl">


Name : <input ng-model="name" /><br/><br/>

Age : <input ng-model="age" /><br/><br/>

Adress : <input ng-model="adress" /><br/><br/>

<input type="button" value="Send" ng-click="postdata(name, age, adress)" /> <br/><br/>


<p>Output Message : {{msg}}</p>

<p>StatusCode: {{statusval}}</p>

<p>Status: {{statustext}}</p>

<p>Response Headers: {{headers}}</p>




Now we will run and see the output of above angularjs $ method that would be like as shown following.

Output of AngularJS $ Service Example

Following is the result of using $ service in angularjs application.


Angularjs $http post service example result or output


If you observe above output we got message like "Service not Exists" that means the url which we defined in angularjs $ method not exists that's why it's showing error message. In case if service exists with that url it will execute and will show message like "Post Data Submitted Successfully".


This is how we can angularjs $ method to send or insert data in remote http servers.