Folks,
I am having a hard time understanding how to write a resource in AngularJs. I have currently written a factory method as below:
var baseUrl = "http://www.myBaseUrl.com/cgi-bin/angular-portal/backend.pl";
myApp.factory('Employee',['$http',function($http){
var employeeUrl = baseUrl + "?getemployeelist";
return{
query: function(){
return $http.get(employeeUrl);
},
get: function(empId) {
return $http.get(employeeUrl + '=' + empId)
}
};
]);
How do I include a POST call in this ? Currently I am making a POST call directly in the controller and as I understand this is not the way to do it:
function EmployeeAddCtrl($scope,Employee,$routeParams) {
// Add a new employee
$scope.addOrUpdate = function() {
var jsonString = angular.toJson($scope.employee);
//Make the REST call
$http.post(postUrl,jsonString)
.success(function(data,status,headers,config) {
// show success message here
})
.error(function(data,status,headers,config){
// DO SOMETHING HERE.. FIGURE LATER
});
}