angularjs - Using [] square brackets as part of a parameter in $resource GET call to API in Angular is not working -
i trying trying user data ajax-localized rest api wants parameters so:
/api/activity?filter[user_id]=1
i have factory set query parameters so:
angular.module('app') .factory('activity',function($resource){ return $resource(ajaxinfo.api_url+'activity', { // query parameters filter: { '[user_id]': '@userid' }, }, { 'query':{ method:'get', headers: { 'x-wp-nonce': ajaxinfo.nonce }, isarray: false } }); })
i'm console.logging in template so:
$scope.userone = activity.query({userid:1}); console.log($scope.userone)
it's returning
http:site.dev/api/activity?filter=%7b%22%5buser_id%5d%22:%22@userid%22%7d&userid=1".
any idea i'm doing wrong?
here's did fix this:
i created factory called "currentuser" factory returns current user's object api.
then created controller passed parameters activity factory when wanted filter activity user id.
$scope.userinfo = function(){ //call currentuser , see if it's available , return u currentuser.instance().then(function(u) { //now query activity factory , pass filter string along user id u.id activity.query({'filter[user_id]':u.id}, function(res){ $scope.userone = res ; console.log($scope.userone); }); }) }; $scope.userinfo();
Comments
Post a Comment