从angular8发出post请求

从angular8发出post请求,angular,Angular,我正在尝试从angular发出http post请求,但请求不是 发送到api,我做错了什么?如何将响应保存为Json对象 import {HttpClient} from '@angular/common/http' @Injectable({ providedIn: 'root' }) export class ApiService { static url: string = 'api url...' constructor(public httpClient: HttpCl

我正在尝试从angular发出http post请求,但请求不是 发送到api,我做错了什么?如何将响应保存为Json对象

import {HttpClient} from '@angular/common/http'
@Injectable({
  providedIn: 'root'
})

export class ApiService {
  static url: string = 'api url...'
  constructor(public httpClient: HttpClient) { }
  addUser(fullName, gender, ID, phone, email, notes, pass) {
    let response
    return this.httpClient.post(ApiService.url, {
      "full_name": fullName,
      "gender": gender,
      "email": email,
      "id": ID,
      "phone": phone,
      "notes": notes,
      "password": pass
    })
  }}
组成部分:

import { Component, OnInit } from '@angular/core';
import {SignupForm} from '../signup-form'
import { ApiService } from "../api.service";

@Component({
  selector: 'app-signup',
  templateUrl: './signup.component.html',
  styleUrls: ['./signup.component.css'],
})
export class SignupComponent implements OnInit {
  form = new SignupForm('', '', '', '','','','')
  submitted= false
  Response
  constructor(private logUser : ApiService) { }
  ngOnInit() {
  }
  getForm()
  {
    return JSON.stringify(this.form)
  }
  onSubmit()
  {
    this.submitted = true;
    this.Response = this.logUser.addUser(this.form.fullName, this.form.gender, this.form.ID,this.form.pass,this.form.email,this.form.notes,this.form.pass)
  }
}

谢谢你的帮助

您忘了订阅post call 像这样做

 this.logUser.addUser(this.form.fullName, this.form.gender, this.form.ID,this.form.pass,this.form.email,this.form.notes,this.form.pass)
.subscribe( data => {
            this.Response = data;
            }

你忘了订阅post call 像这样做

 this.logUser.addUser(this.form.fullName, this.form.gender, this.form.ID,this.form.pass,this.form.email,this.form.notes,this.form.pass)
.subscribe( data => {
            this.Response = data;
            }

您的服务(ApiService)中的addUser方法正在返回一个可观察的。因此,为了操纵post-api调用响应,您需要像下面这样对其进行分类

onSubmit()
  {
    this.submitted = true;
    this.logUser.addUser(this.form.fullName, this.form.gender, this.form.ID,this.form.pass,this.form.email,this.form.notes,this.form.pass).subscribe(resp =>  {this.Response = resp} )
  }

您的服务(ApiService)中的addUser方法正在返回一个可观察的。因此,为了操纵post-api调用响应,您需要像下面这样对其进行分类

onSubmit()
  {
    this.submitted = true;
    this.logUser.addUser(this.form.fullName, this.form.gender, this.form.ID,this.form.pass,this.form.email,this.form.notes,this.form.pass).subscribe(resp =>  {this.Response = resp} )
  }

谢谢但它仍然没有到达api,(我可以在postman中发出请求,所以我猜这是代码的原因)它说[Error]XMLHttpRequest由于访问控制检查而无法加载“url”。谢谢!但它仍然没有到达api(我可以在postman中发出请求,所以我猜这是代码的问题),它说[Error]XMLHttpRequest由于访问控制检查而无法加载“url”。