0

I am consuming this Rest web service from my AngularJS application and I'm using $resource to pass parameters and get my data.

I have a particular service that can take the same parameter multiple times like this in my Postman session:

/myService/Accounts?acctId[]=7029&acctId[]=3324

I've tried to pass a generated string to my $resource query methods placeholder but it ends up escaping all my brackets and not working.

I also tried not using a placeholder and passing the same parameter twice, it doesn't fail but it takes the last value so that does not work either.

    $scope.resultsColl = rfpService.searchAccountName.query({

      acctName: $scope.accountName,
      acctRole: acctRoleParams,
      acctRole: acctRoleParams2


    });

Hopefully someone has had this same issue? Any ideas?

haakon.io
  • 477
  • 6
  • 19
  • Did you see this answer http://stackoverflow.com/questions/28115354/how-to-add-multiple-same-name-query-parameters-in-angular-http ? – NBeydon Apr 19 '17 at 13:15

1 Answers1

0

From the research I've done on other posts it looks like you can't dynamically generate using $resource. My working solution was to switch to $http, this way I could dynamically generate multiple acctRole[] params:

  var acctRoleParams = '';

  if(corporate === true)
  {
    acctRoleParams = '&acctRole[]=C';
  };

  if(smallBiz === true)
  {
    acctRoleParams += '&acctRole[]=B';
  };

    $http.get("https://myRestServiceUrl/services/customer/accounts?acct=" + $scope.account + acctRoleParams)
      .success(function (data, status, headers, config) {
        $scope.gridOptions.data = data.data.detailsByAcct;
    })
      .error(function (data, status, headers, config) {
      showToast("An error occurred during the request");
    })
      .finally(function () {
        $scope.isGridLoading = false;
      });

I wanted to post this in case anyone else has been struggling to do the same thing.

haakon.io
  • 477
  • 6
  • 19