I got a Service who returns some values from a database. Works well: ( The service is called Friends)
get: function(friendId) {
// $http returns a promise, which has a then function, which also returns a promise
promise2 = $http({
url: "http://dev.tellthedj.de/db/getGutschein.php",
method: "POST",
data: {"gutscheinId":friendId}
}).then(function(response2) {
// The then function here is an opportunity to modify the response
// The return value gets picked up by the then in the controller.
return response2.data;
});
// Return the promise to the controller
return promise2;
}
This service is returning the right values for my purpose in correct json. Now I need to show this values in my view. Therefore I got this controller:
.controller('FriendDetailCtrl', function($scope, $stateParams, Friends) {
Friends.get($stateParams.friendId).then(function(b) {
$scope.friend = b;
console.log($scope.friend);
});
})
This should be right it think! This is the HTML
<ion-view title="{{friend.name}}">
<ion-content has-header="true" padding="true">
{{friend.id}}
{{friend.name}}
</ion-content>
</ion-view>
The window is empty. No friend.id, no friend.name. Can´t find the mistake...
UPDATE: Setting {{friend}} or {{friend | json}} is writing the complete returned json data in the view. When I try {{friend.name}} (which is inculded in that json object) there is no return.
The returned Object from the $http service ist exactly the same, like another Object from another Web-Service that works!