Getting error: GET https://localhost:5001/api/users net::ERR_CONNECTION_REFUSED | In Angular 18

Discussão em 'Angular' iniciado por Priyanka Joshi, Janeiro 25, 2025.

  1. client is running at http://localhost:4200/ and server listening on: http://localhost:5245 getting this error after restarting server as well Error: HttpErrorResponse {headers: _HttpHeaders, status: 0, statusText: 'Unknown Error', url: 'https://localhost:5001/api/users', ok: false, …}

    app.components.ts

    ` import { HttpClient } from '@angular/common/http';
    import { Component, OnInit, inject } from '@angular/core';
    import { RouterOutlet } from '@angular/router';

    @Component({
    selector: 'app-root',
    standalone: true,
    imports: [RouterOutlet],
    templateUrl: './app.component.html',
    styleUrl: './app.component.css'
    })
    export class AppComponent implements OnInit {
    // Declare users as an array of any type
    users: any;

    http = inject(HttpClient);
    title = 'Angular 18';

    ngOnInit(): void {
    this.http.get('https://localhost:5001/api/users').subscribe({
    next: response => this.users = response,
    error: error => console.log(error),
    complete: () =>console.log("Request has completed")
    })
    }
    }`


    client and server side port are running already, i am expecting a success message on console

    Continue reading...

Compartilhe esta Página