Я пытаюсь отправить http-запрос из моего angular приложения в API, но получаю «[Ошибка] XMLHttpRequest не может загрузить 'url' из-за проверок контроля доступа.", Компонент:
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).subscribe(resp => {this.Response = resp} )
}
}
услуга:
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
})
}}
как я могу это исправить? спасибо!