title: Angular js $http example Web API
body: <p>Here is my API controller method</p>
  
  <pre><code> [HttpPut]
  
          public List&lt;Employee&gt; PutEmployee(int EmpID, Employee empl)
          {
              empl.EmpID = EmpID;
              int index = emp.GetEmployees().FindIndex(i =&gt; i.EmpID == empl.EmpID);
              emp.GetEmployees().RemoveAt(index);
              emp.GetEmployees().Add(empl);
              return emp.GetEmployees();
          }
  </code></pre>
  
  <p>Here is angularJS controller</p>
  
  <pre><code>   $scope.UpdateEmp = function () {
          var empl = $scope.Employee;
          empHttpFactory.update(empl.EmpID,empl ).success(function () { // update method in my resource uses $resource
              $location.path('/EmpList'); //redirect to list
          });
  
      };
  </code></pre>
  
  <p>Here is my service code</p>
  
  <pre><code> var resource={
          update: function (ID, empl) {
  
             // var empl = {'EmpID':1,'FirstName':'Kailash', 'Salary':62000};
              var params = { EmpID: ID, empval: empl };
  
                           // return $http.put('../api/Emp/Put', { EmpID: ID , empval:   return $http({
                  method: 'PUT',
                  url: '../api/Emp/Put',
                  data: params
  
              })
  </code></pre>
  
  <p>empl });</p>
  
  <pre><code>        }
      }
  
      return resource;
  </code></pre>
  
  <p>When i do the debug, i could see the value for EMPID and empval in the angularjs controller and service but when it comes to API controller part, i m getting the value for EMPID alone but not for empval, its coming as null. can someone provide me working sample of it. i m new to AngularJS</p>
  
  <p>Update 1 :</p>
  
  <p>I have replaced the Params to data in my http call. My API method expecting the parameter in the body as per my controller method. I changed the http call accordingly and it started working fine. Also in my first argument to the controller method, I m using the variable name as EmpID, if I have used as "id", then probably, id would have been passed as the parameter in the URL itself</p>
  
  <pre><code> return $http({
                      method: 'PUT',
                      url: '../api/Emp/Put',
                      data: params
  
                  })
  </code></pre>
  
  <p>Updated Question:
  This is regarding the $resource</p>
  
  <p>In $resource documentation, 2nd argument is parameter and the 3rd has list of actions where I can mention the parameters. But if you see from my example, I haven't explicitly used params option but passing data to my controller method. Its working as expected because its taking it as data. Why it so???</p>
  
  <p>$resource('../../Employee/PutEmployee/', {  }, { update: { method: 'PUT', empval: { "EmpID": 1, "FirstName": "John", "LastName": "Peter", "Salary": 60000 } ,isArray: true } })</p>