I have a service that adds a new record into the database.
return $http.post('/models/CreateModel', userObj)
.then(function (res)
{
// Return the new model_id
return res.data;
},
function (err)
{
// console.log("THERE WAS AN ERROR");
});
The value in res.data is the new primary key number. That is returned to the controller as follows:
$scope.newID = ModelService.addModel(xMdl);
When I print out $scope.newID using console.log, I see that it contains an object rather than the value. The object looks like the following in my console:
- d {$$state: Object}
- $$state: Object
status:1
value: 232
- __proto__: Object
- __proto__: Object
How do I access the value 232 as I need to update the id in the angular model with this?
$http.postreturns... to access the promised value, you need to do.then(function(data){$scope.newID = data}).