I'm trying to implement an asynchronous follow/unfollow function.. just like in instagram when you pull up the list of your followers there's an 'following'/'follow' button associated to each item.. for brevity i made the code simple. I'm using ionic framework
my code in the view:
<ion-list>
<ion-item ng-repeat="user in users">
<span ng-click="followUser(user.id, indexHowTo??)">Follow</span>
<p>{{user.name}}</p>
</ion-item>
</ion-list>
$scope.followUser = function(userid, indexHowTo) {
var to_from = {
to_user: userid,
from_user: $localStorage.CurrentUser.id
}
UserService.FollowUser(to_from, $localStorage.CurrentUser.auth_token)
.success(function(data) {
$scope.users[index].is_following = true; //i'll do something in the view just didn't show for brevity
}).
error(function(error, status) {
//alert(status);
console.log(error);
});
}
$index. Using the$indexmay pose problems if you use filters in yourng-repeatstatement.