I have 3 blocks that are showed based on a boolean.
<button ng-if="user.friendship == null" ng-click="requestFriendship(user.user.id)" class="button button-outline button-calm">
Invite as friend
</button>
<button ng-if="user.friendship == false" ng-click="removeFriendship(user.user.id)" class="button button-calm">
Friend request sent
</button>
<button ng-if="user.friendship == true" ng-click="removeFriendship(user.user.id)" class="button button-calm">
Unfriend
</button>
Well at first i don't know if it is the best solution to structure it that way, so do not hesitate to correct me here if i'm wrong.
then i have my function :
$scope.requestFriendship = function(id) {
$http.post(domain+'/api/friendship/request/'+id+'?access_token='+access_token.key).then(function(response){
// If success change button
}, function(error) {
console.log(error);
});
}
$scope.requestFriendship = function(id) {
// function
}
So based on the result (my api is returning success or failed, so if success), I need to Hide the previous button and change it to its new state.
So how can i hide and show buttons based on the answer of the API.