0

I have an Angular 1 application where a user can select several items by clicking on a checkbox. When he clicks a particular button, these Ids are aggregated as this:

angular.forEach($scope.orders, function (order, id) {
    if (order.export) {
        ids.push(order.id);
    }
});

Now I want to query these Ids in my php api action, but how can I transmit all id's to my apiAction? I tried it with $http.query ($scope.items = Items.query({ 'ids' : ids});), but this does not work as it creates a strange url which can not be parsed.

Then I tried it with: $http.save and there I can transfer the ids to my api action, but I also need to return the result back to my application in order to show it on the frontend, but with using $http.save this does not seem to be possible, as I always get a orderBy:notarray error.

So how can I use $http.save and get a proper array in return or use $http.query with an array with multiple ids in the params?

Thanks

1

2 Answers 2

2

In angular $http call...

params: {
    id: JSON.stringify(ids) 
  }

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm, then I get this query result: itemsApi?ids=%5B1816,1817%5D When I do var_dump($ids); I get this result: string(11) "[1816,1817]" So I need to substr [ and ] and then do an explode. Or is there another solution?
0

You can convert your array into comma separated string and then pass that string into your php api and then you can get back your array in php. E.g.,

Angular side,

ids.toString()

PHP side,

explode(",",$query_param);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.