I have a service that returns JSON, assume this is the response:
{
"model": 48870,
"id": 20
}
I can do this:
$scope.response = Service.get();
And it will assign the JSON response to $scope.response. The issue here is I cannot directly access model or id via $scope.response.model or $scope.response.id, respectively. My workaround for this situation is to define a function in the service's success callback and fetch model or id from data. But this is not very practical considering $scope.response contains the entire JSON object and should in theory (and the sake of clean code) let me access its children.
Two questions here:
- Is it a limitation of AngularJS representation of models?
- How can I point to children (even grandchildren) without having to define a success callback for each call?
$scope.response.modelis loaded before using it (e.g., success callback), otherwise you'll be getting a ReferenceError.