Using TypeScript to pass an array list as a parameter in the HTTP native GET method

Attempting to send an array list parameter. The codeList parameter contains an array like this:

[
  {
    "projCode": "11-1115",
    "cblTagNo": "571_GE001-RC1"
  },
  {
    "projCode": "11-1115",
    "cblTagNo": "571_GE001-S"
  }
]

Encountering the error message

"invalid params object, needs to be an object with strings"
. How can I correctly pass the obj array? Here is the http call method being used.

checkCableTagList(codeList: String[]){
  this.http.setDataSerializer('json');
  console.log(JSON.stringify(codeList));
  return this.http.get('http://hostname/cable/v2/cableschedule/key/', codeList, {});
}

I also tried the following approach, which was unsuccessful.

return this.http.get('http://hostname/cable/v2/cableschedule/key/', JSON.stringify(codeList), {});

Answer №1

To easily send this array, utilize the HttpParams method.

   let httpParams: HttpParams = new HttpParams();
   codeList.forEach(code => httpParams = httpParams.append('Projects', code ));

 //Send HTTP request-
 return this.http.get('http://hostname/cable/v2/cableschedule/key/', {
   params: HttpParams 
 }).subscribe(
   (response) => //manipulate response here 
 );

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Execution of the console.log statement occurs following the completion of the request handling

When I have a piece of middleware that responds if no token is found, why does the console.log line still run after the request is responded to? I always believed that the res.json call would "end" the middleware. Any insights on this behavior would be g ...

Sending files via an Ajax request triggers an unexpected page refresh

I have limited experience with ajax, but I am encountering an issue when trying to send form data to an ASP controller. Scenario 1 When I set data in the ajax request to $(this).serialize() All form data is successfully posted to the controller withou ...

Exploring FormArray Validation in Angular 6

Managing around 50 controls on my page, especially when it comes to validation, is a bit overwhelming. I find myself repeating the same Validators for each control. I'm considering grouping the validators into two categories: 1. [Validators.required ...

Adjusting editable property in FullCalendar during script execution

Currently, I am working with Angular JS and fullCalendar to customize the functionality of my calendar. My goal is to change the editable property of the calendar when a button is clicked. Although it seems like a straightforward task, I am facing difficul ...

How can one address the issue of undefined data within table cells?

I have encountered an issue while reading and displaying an XML file on a webpage using a JavaScript script. The problem arises when the page loads, and the information inside the cells of the table shows as "UNDEFINED". The intended display should include ...

Verify for a class that does not exist

I am working on a script that updates the content of a div and increments its value by 1 $(function() { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'), }, }); ...

Clicking 'Submit' triggers a continuous loop upon loading

I set up this form to automatically submit once the page has finished loading. However, I seem to be encountering a problem where the page gets stuck in a continuous loop of reloading. HTML <body onload="document.getElementById('filters').su ...

Merging Promises in Typescript

In summary, my question is whether using a union type inside and outside of generics creates a different type. As I develop an API server with Express and TypeScript, I have created a wrapper function to handle the return type formation. This wrapper fun ...

Express 4: The requested route was not found by the router

Encountering a peculiar issue - the initial route functions properly, but when trying the parameterized route, a 404 error is returned. const express = require('express'); const router = express.Router(); router.route('/') .get(fu ...

Error: Unable to execute 'surroundContents' on 'Range': The selection within the Range is only partially on a non-Text node

Hello, I’m working on creating a text reader that allows users to highlight text in multiple colors. I’ve already written the code and you can check it out in the sandbox at the link below: https://codesandbox.io/s/gallant-snowflake-oxko7?file=/src/Ap ...

Having difficulty with loading images lazily in a jQuery Mobile app with LazyLoadXT feature

Struggling to incorporate lazy loading in my jQM app with Lazy Load XT v1.0.6. Oddly, images only appear when switching browser tabs, not while scrolling down. This happens on Firefox and Chrome. <img src="/img/default-img.jpg" data-src="/img/product/ ...

Using Jquery to drag and drop items into a specific target zone

Check out my Jquery code: $(".list").draggable({helper: 'clone', cursor: 'hand'}); $(".drop1").droppable({ accept: '.list', hoverClass: 'dropareahover', drop: function(ev, ui){ var targetId = $(this) ...

The subscription for the second Observable in RxJS concatMap is triggered individually

I am currently developing an Angular 6 application. I want the app to display a loading animation whenever there is a change in the route or if there are any pending HTTP requests. To achieve this, I have set up two Observables as follows: For httpPendingR ...

Traverse through JSON data within a view

I am currently learning how to use the MEAN full-stack and have encountered a problem that I can't seem to find a solution for. When iterating over the JSON object using ng-repeat, everything works fine except when trying to use the x.url variable in ...

What could be causing this JSON object error I'm experiencing?

res.send({ customerDetails:{ fName, lName, }, applicantDetails:{ [ {primaryApplicant:{fName1,lName1}}, {secondaryApplicant:{fName2,lName2}}, {thirdA ...

Effortless method for distributing NPM-loaded modules among various Browserify or Webpack bundles

Feeling frustrated trying to find a straightforward way to share code, required via NPM, across multiple Browserify or Webpack bundles. Is there a concept of a file "bridge" that can help? I'm not concerned about compile time (I know about watchify), ...

Switching perspective in express with Pug

Hello everyone, I'm still getting the hang of using Node.js with Express and Jade. I've successfully set up a basic 1 page app where a login page is displayed by default. Once the user logs in and is authenticated against a database, the function ...

Unable to load custom package in Angular 2 testing environment

I've been following the official Angular 2 testing guide on an existing project. Everything runs smoothly when I use my custom library, downloadjs, in the application. However, I encounter an error in the console during test execution: "__zone_symbol ...

What is the best way to incorporate template literals (` `) into existing template literals?

I am facing a unique challenge where I need to utilize a template literal within another template literal, but I am struggling to make it work. The code snippet in question looks like this: <p>Something something <a href={`${SOMELINK}/blah`}> ...

CDK Error: Unable to locate MethodResponse in AWS API Gateway configuration

I'm facing an issue in vscode while trying to access the MethodResponse interface from apigateway. Unfortunately, I'm getting an error message: The type 'typeof import(".../node_modules/aws-cdk-lib/aws-apigateway/index")' d ...