Having trouble retrieving information from a controller action in .NET Core and Angular 2

My Angular 2 service:

private checkEmailAvailabilityUrl = 'api/admin/checkemailavailability';
checkEmailAvailability(email: string): Observable<boolean> {
    let params = new URLSearchParams();
    params.set('email', email);
    return this.http
        .get(this.checkEmailAvailabilityUrl, { search: params })
        .map((response: Response) => {
            return this.extractData(response);
        });
    }

My controller action:

[Route("[action]")]
[HttpGet]
public async Task<IActionResult> CheckEmailAvailability(string email)
{
    return Json(new Json("success", false));
}

I set a breakpoint in Visual Studio, but the application does not reach it. I also attempted to include [FromQuery] for email, but it did not resolve the issue. What steps should I take to address this?

Answer №1

According to the details provided in the Documentation

The http.get method does not immediately send the request. It is mentioned that this Observable is considered cold, indicating that the request will only be sent once something actually subscribes to the Observable.

This implies that it is essential to subscribe to your Observable. Ultimately, you must invoke the subscribe function on it to trigger the actual request.

private verifyUserEmailUrl = 'api/admin/verifyuseremail';

verifyUserEmail(email: string): Observable<boolean> {
    let params = new URLSearchParams();
    params.set('email', email);
    return this.http
        .get(this.verifyUserEmailUrl, { search: params })
        .map((response: Response) => {
            return this.extractData(response);
        })
        .subscribe((data) => /* Your code here */);
    }

Answer №2

It appears that your controller has incorrectly mapped the URL. Please refer to the correct mapping provided below.

[Route("api/admin/verifyuseremail")]

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

Encapsulate the HTTP request within a common function for reus

My rest-provider service handles all of my http calls, but I've noticed that each function is repeating a lot of the same http code. It seems like I should create a shared function to avoid this repetition and make it easier to update in the future. ...

agm-polygon fails to refresh with new points added

I've recently switched from using Google maps to AgmMaps and wanted to create a simple demo for drawing polygons on the map. Here's what I added to my project: You can find the stackblitz link with the code here <agm-polygon [strokeColor]="& ...

The application within the Main Module is not being acknowledged by the other components within the module

I am facing an issue with my AngularJS application where the directive I created within the 'FormTest' module is not recognizing the variable 'app' even though it is defined within the same module. The error message I receive is TS2304 ...

The type of Object.values() is not determined by a union or Records

When utilizing TypeScript, the Object.values() function encounters issues in deducing the accurate type from a union of Records: type A = Record<string, number>; type B = Record<string, boolean>; function func(value: A | B) { const propert ...

Reusing Angular components multiple times within a single template - dynamically adding lists within them

I created this new component that includes a table (which is an array of key-value pairs) and a form below it. The form is designed to add new values to the table. Here is the Angular code I used: @Component({ selector: 'app-key-value-table', ...

Can you identify the specific function type passed through props?

interface IProps { handleCloseModal: React.MouseEventHandler<HTMLButtonElement> returnFunction: () => void; } export default function Modal({ children, returnFunction, handleCloseModal, }: React.PropsWithChildren<IProps>) { cons ...

Utilize Typescript with React to efficiently destructure and spread objects

My goal is to maintain my child components as stateless (functional components). Therefore, I am in search of an efficient way to pass down the root component's state values to its children. For example, interface IState { a: string; b: number; ...

Warning: Obsolescence of Typescript Detected

Having an issue with my login code in TypeScript. The 'subscribe' function is deprecated and I'm not sure how to proceed. Can anyone provide some guidance? doLogin() { this.userService.doLogin(this.loginForm.value).subscribe( r ...

Encountering issues with managing CometD channels within Angular 2

After dabbling in Angular2 and Typescript, I decided to challenge myself by creating an application using plain javascript with the CometD library. The goal of this app was to retrieve data from a CometD channel and present it to the user in some way. So, ...

What is causing the warnings for a functional TypeScript multidimensional array?

I have an array of individuals stored in a nested associative array structure. Each individual is assigned to a specific location, and each location is associated with a particular timezone. Here is how I have defined my variables: interface AssociativeArr ...

Get the socket identification from ngx-socket-io

After incorporating ngx-socket-io into my project, I encountered a hurdle while attempting to obtain the socket id. Is there anyone who has knowledge on how this can be accomplished? (I am utilizing service initialization instead of the one in the app Mo ...

Analyzing a Typescript project using SonarQube Scanner on a Mac OS slave in Jenkins: A step-by-step guide

My current task involves examining a TypeScript project on Jenkins using the SonarQube Scanner plugin on a Mac OS slave. Software: Jenkins (version 2.32.1) SonarQube Scanner for Jenkins plug-in (version 2.5) SonarQube Scanner (version 2.8) SSH slave plu ...

Tips for injecting a service into a class (not a component)

Can you inject a service into a class that is not a component? Consider the following scenario: Myservice import {Injectable} from '@angular/core'; @Injectable() export class myService { dosomething() { // implementation } } MyClass im ...

There is a chance that the object could be 'undefined' when attempting to add data to it

I created an object and a property called formTemplateValues. I am certain that this property exists, but I am getting an error message saying: "Object is possibly 'undefined'". It should not be undefined because I specifically created it. Why am ...

Exploring the Power of Dynamic XML in Your Angular 4/5 Application

If example.com is an active angular 4 application with existing routes such as /product and /category, how could I create a route like /products.XML or /category.xml to display dynamic XML content for each. ...

Using Angular and Typescript to implement mathematical formulas involving date object subtraction

I need help converting the following Excel formula to Typescript. I keep running into an error that says 'The left-hand and right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type'. Can anyon ...

What steps can I take to set a strict boundary for displaying the address closer to the current location?

While the autocomplete feature works perfectly for me, I encountered an issue where it suggests directions away from my current location when I start typing. I came across another code snippet that uses plain JavaScript to solve this problem by setting bou ...

Steps to deactivating a styled button using React's styled-components:

I've created a very basic styled-components button as follows: import styled from 'styled-components'; const StyledButton = styled.button``; export const Button = () => { return <StyledButton>Default label</StyledButton> ...

Count of items in filtered data displayed using Angular 5 *ngFor

Looking for help with my ngFor loop: *ngFor="let item of items | filterBy: ['SN', 'Name']: userFilter | orderBy: order | paginate: {itemsPerPage: 10, currentPage: 1}; let i = index;" Trying to retrieve the count of filtered items. Whe ...

What strategies can be utilized to manage a sizable data set?

I'm currently tasked with downloading a large dataset from my company's database and analyzing it in Excel. To streamline this process, I am looking to automate it using ExcelOnline. I found a helpful guide at this link provided by Microsoft Powe ...