Error connection with my Rest API

I can not communicate with my api in the server
i get this message error
no ‘access-control-allow-origin’ header is present on the requested resource

 public login() {
    this.auth.login(this.registerCredentials).then((result) => {
    }, (error) => {

auth.ts (login Service)

    return new Promise((resolve, reject) => {
      let headers = new Headers(); , JSON.stringify(credentials), {headers: headers}).
      subscribe(res =>{
      }, (err) =>{

This is likely due to a CORS issue, which you need to resolve at server side. There is an abundance of postings on this forum telling you how to solve it at server side

Secondly, your login pattern seems a bit over the top in terms of coding. First of all, why convert an Observable to a Promise (Observables are the next-gen Promise)? Secondly, if you insist, you can do it like this (and not sure why you need to incllude empty headers)

    return , JSON.stringify(credentials))
1 Like

tkx a lot i’ll try the CORS issue
i used promise cuz i just want to resolve the probleme if not I did as you did
for the headers i will fill it after