I am facing an issue where I am trying to pass an object to my controller using the $http method, but even though the object has a value, the data being passed is showing as NULL. Below is the code snippet that demonstrates this problem.
Within my JavaScript file, I have initialized an object like so:
$scope.emp = {
Name: null,
Age: null
};
I am capturing values for this object in a form, so 'this.emp' should hold some data.
When I click on a submit button, I am attempting to send this data to my controller using the HTTP method in the following way:
// On my HTML page
<button type="submit" ng-click="saveForm()" >Submit</button>
// Within my JavaScript file
$scope.saveForm = function() {
try {
$http({
url: 'Employee/SaveEmployee',
method: "POST",
data: this.emp,
}).success(function(response) {
});
} catch (e) {}
}
While debugging, I can see that 'this.emp' contains a value, but the 'data' being sent is showing as NULL. As a result, the value received by my Controller method is also NULL. Can you please help me identify the error?