如何从ng-click获取价值,发送到laravel进行查询?
//。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 => this part has to be from ng-click value**)
->orderBy('c.created_at','asc')
->get();
return Response::json($comments);
}
答案 0 :(得分:0)
您已在ng-click功能中传递
recipient.id
参数但未在js函数中检索参数
您需要检索参数
$scope.select = function(**id**) {
var selectedId=id;//you can check here
Comment.get()
.success(function(data) {
$scope.comments = data;
$scope.loading = false;
});
}
答案 1 :(得分:0)
对于使用$http.get
方法传递数据,您可以使用[config]
的第二个参数。
请参阅: https://docs.angularjs.org/api/ng/service/ $ http#get以获取有关get方法的更多参考