'http.post request in Angular not reaching web api controller

I'm working on Angular 11 and having trouble in http.post request. I'm trying to send form data model to .net core API for DB processing. But for some reason the code is not reaching api controller.

Below is the code, software-new-list-request-view.ts

export class SoftwareProductListRequest
{
   softwareProductListId:number;
   name:string;
   description:string;
   owner: string;
   referenceKey:string;
   softwareProductIds: number[];
}

software-list.component.ts

import { SoftwareProductListRequest } from '../../../models/software-new-list-request-view';

export class SoftwareListNewRequestComponent implements Onit {
model:SoftwareProductListRequest = new SoftwareProductListRequest();
this.softwareListService.requestNewSoftwareList(this.model)
.subscribe((result)=>{items=response;});
}

this.model in the above code has the form field data.

software-list-service.ts

requestNewSoftwareList(request) : Observable <object> {
  this.http.post<object>('https://localhost:44390/api/SoftwareList/request-new-list',requestNewList).pipe();
}

SoftwareListController.cs

[HttpPost("request-new-list")]
public object RequestNewSoftwareList(SoftwareProductListRequest request)
{
  //call DAL layer for DB save
}

I tried having an Observable in Angular http.post call. The code does not even hit the api controller. Any help in resolving this problem is much appreciated. I tried adding catching the error with a catch block as well, but that code is also not executed.

Thanks in advance, Sushma



Solution 1:[1]

You should return observable in requestNewSoftwareList.

requestNewSoftwareList(request){
  return this.http.post<object>('https://localhost:44390/api/SoftwareList/request-new-list',requestNewList);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 N.F.