angular 在本地调用节点后端时,http 客户端无法正常工作?

angular http client is not working when calling node backend locally?

尝试使用 angular http 客户端调用 nodejs 本地主机,但它没有到达后端 我在 angular 应用程序的 proxy.config 中添加了 url 作为我在问题中添加了任何想法都不起作用?

angular service.ts

import { Injectable } from '@angular/core';
import { HttpClient , HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({providedIn: 'root'})
export class AdminService {

  constructor(private http: HttpClient) { }

  private  url = "http://localhost:9001/api/saveClients";

  saveClientJobs(data) {
        let options = this.createRequestOptions();
        console.log("Service", data);
        return this.http.post(this.url, data, { headers: options });
    }

    private createRequestOptions() {
        let headers = new HttpHeaders({
            "Content-Type": "application/json"
        });
        return headers;
    }
}

angular proxy.config.json

{
  "/api/*":{
      "target":"http://localhost:9001",
      "secure":false,
      "logLevel":"debug",
      "changeOrigin": true
  }
}

NodeJs 路由

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const admin_controller_1 = require("./api/admin/admin.controller");
class RegisterRouteClass {
    RegisterRoutes(app) {
        app.post('/api/saveClients', admin_controller_1.AdminController.save);
       
    }
}
exports.RegisterRouteClass = RegisterRouteClass;

为了执行 post/get,您需要订阅它。如果您没有订阅 post/get,它将永远不会执行,因此开发者工具的网络选项卡中不会输出任何内容。

saveClientJobs(data).subscribe(result => /* do something with the result */)