我正在使用 laravel 和 angularjs 开发一个社交应用程序。
我有一种情况,当我使用助手检查用户关系时。
**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;
}
}
现在,如果用户不是当前用户的朋友,那么它将被相应地添加。现在的问题是我如何在用户点击它而不重新加载页面时反映 {=checkrelation(data.id)=} 中的变化,因为在页面加载时我会看到 chnages在文本上。任何帮助都会有所帮助。