0

I am working on an Social app using laravel and angularjs.

I have a situation where when i check for user relation using helper.

 **Html**


     //showing users other info    

     <div ng-repeat="user in data">
     <a ng-click=checkuser(user.id,checkrelation(user.id))>
       {=checkrelation(user.id) =} <a>
     </div>

 **js**

 //scope to hold user's data
 //i get this info using service for the visiting user
 $scope.data = myservice.userinfo();

 //scope to hold users current subscriber info using service
 $scope.allsubscriber = myservice.usersubscriber();

 //check user relation and return text accordinglly
 $scope.checkrelation = function(id){
 //if user found
 if($scope.allsubscriber.indexOf(id) != 1){
  return "fellow";
 }else{
 // not found
 return "subscribe";
}

}

$scope.checkuser = function(id,text){
   if(text === "subscribe"){   
  //make ajax call to save user subscriber
  //here i want to reload the user status which is checked by helper
 }else 

 return false;

  }
  } 

Now if user is not current user's friend then it will be added accordingly.Now question is how can i reflect changes in {=checkrelation(data.id)=} as user's click on it without making page reload because on pageload i cam see chnages on text. Any help would be helpfull.

Anil Sharma
  • 2,952
  • 5
  • 29
  • 45

1 Answers1

0

Angular templates provide you with $event, which you can pass into your callback. This allows you to do $event.preventDefault(), which will override that default <a/> click.

example:

<a href="#/whatevz" ng-click="myFunc(thing1, $event)">link text</a>

then in your controller:

$scope.myFunc = function(thing, e){
   e.preventDefault();
   /*do stuff with thing*/
}

edit: preventDefault() is part of the DOM spec

J.Wells
  • 1,749
  • 12
  • 13