javascript - How to pass value from ng-click (AngularJS) to Laravel? -


how value ng-click , send laravel query?

//.html

<div ng-controller="recipientscontroller">         <div ng-repeat="recipient in recipients | orderby:'-created_at'" ng-click="select(recipient.id)">             <p class="recipientname">{{ recipient.name }}</p>         </div>     </div> 

//xxcontroller.js

$scope.select = function() {     comment.get()         .success(function(data) {             $scope.comments = data;             $scope.loading = false;         });  } 

//xxservice.js

get:function(){         var comments = $http.get('api/comments');         return comments;     }, 

//xxcontroller.php [laravel]

public function index() {        $comments = db::table('c')         ->join('u', 'c.id', '=', 'u.id')         ->select('u.id', 'u.name', 'c.comments', 'c.created_at')         ->where('u.id','=', auth::user()->id)         ->orwhere('u.id','=', **39 => part has ng-click value**)         ->orderby('c.created_at','asc')         ->get();     return response::json($comments); } 

you have passing recipient.id parameter in ng-click function did't retrieve parameter in js function

you need retrieve parameter

$scope.select = function(**id**) {    var selectedid=id;//you can check here     comment.get()         .success(function(data) {             $scope.comments = data;             $scope.loading = false;         });  } 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -