0

私は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)=} の変更を反映する方法です。テキスト上。どんな助けでも役に立ちます。

4

1 に答える 1

0

Angular テンプレートは$event、コールバックに渡すことができる を提供します。これにより$event.preventDefault()、デフォルトの <a/> クリックをオーバーライドすることができます。

例:

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

次に、コントローラーで:

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

edit : preventDefault()DOM 仕様の一部です

于 2014-04-19T17:42:29.403 に答える