I am new to Angular and would like to know how to post data.
I have a controller made in Angular :
myApp.factory('employeeServices', ['$http', function ($http) {
var factoryDefinitions = {
moveToBench: function (employeeId) {
var data = $.param({
json: JSON.stringify({
"entityId": employeeId,
"nextStateId": myApp.state.bench
})
});
return $http.post(myApp.IndecommBaseUrl + '/Workflow',data).success(function (data) {
return data;
});
}
}
return factoryDefinitions;
}
]);
//Controller
myApp.controller('getEmployeesController', ['$scope', 'employeeServices', 'dataTable', function ($scope, employeeServices, dataTable) {
employeeServices.getEmployees().then(function (result) {
$scope.moveToBench = function (id) {
employeeServices.moveToBench(id);
}
});
}]);
I have a button in HTML :
<button class="btn btn-success" ng-click="moveToBench(employee.employee.id)">Move To Bench</button>
On button press, I can see that the values in :
moveToBench: function (employeeId) {
var data = $.param({
json: JSON.stringify({
"entityId": employeeId,
"nextStateId": myApp.state.bench
})
are correct. But while it reaches the API, its value is NULL..
The backend API controller is :
// POST api/values
[HttpPost]
public void Post(int entityId, int nextStateId)
{
JObject jsonObject = JObject.Parse(System.IO.File.ReadAllText("Config.Json"));
string jsonFile = jsonObject.GetValue("WorkfowJsonFileLocation").ToString();
var nextState = _stateServices.Get(nextStateId);
var handler = new WorkflowHandler(nextState, jsonFile, _entityServices, 1, _stateServices, _subStateServices, _appServices);
handler.PerformAction(entityId);
}
Can anyone help me out with this?