Reputation: 33
Hello I have problem with posting JSON to my rest API. ngResource is passing string with qutes it is look like
{"name" : "Jan", "surname" : "Kowalski", "position" : "{"positionid":0}, "id" : 1 }"
but I need it in this way
{"name" : "Jan", "surname" : "Kowalski", "position" : {"positionid":0}, "id" : 1 }
here is my code in jsp :
controller('addNewWorkerController',
['$scope','formService','positionlist',function($scope,formService,positionlist) {
$scope.saveData=function () {
var str= "{positionID:"+$scope.formInfo.position+"}";
$scope.position = str;
window.alert(str);
console.log($scope.formInfo);
formService.save($scope.formInfo);
}
my formService code
service.factory('formService',['$resource',function($resource){
return $resource('http://localhost:8080/workers',{},{
save:{
method:'POST'
}
}
)
}]);
Upvotes: 0
Views: 23
Reputation: 74738
I suppose you need to do this:
$scope.saveData=function () {
var str = {positionID : $scope.formInfo.position }; // <---instead of js object string convert it to js object.
$scope.position = str;
window.alert(str);
console.log($scope.formInfo);
formService.save($scope.formInfo);
}
Upvotes: 1