本地主机在 angular 中的后端 api 之前附加自身

localhost appending itself before the backend api in angular

我已经把我的后端放到 aws 上了。后端 url 在邮递员中工作正常。

但是当我将后端 url 放入 angular 服务时,locahost 会附加到它前面。

我该如何解决这个问题。

后端url:api.angularapp.site

在我的服务中,我这样称呼:


private url = "api.angularapp.site/api/v1";

public signupFunction(data):Observable<any>{

    const params=new HttpParams()
    .set('firstName', data.firstName)
    .set('lastName', data.lastName)
    .set('mobileNumber', data.mobile)
    .set('email', data.email)
    .set('password', data.password)
    .set('gender',data.gender)
    .set('profilePic',data.profilePic);

    return this.http.post(`${this.url}/users/signup`,params);
  }//end of signup function

但是当我 运行 应用程序并尝试注册时,我收到控制台错误:

http://localhost:4200/api.angularapp.site/api/v1/users/signup 404(未找到)

为什么这个本地主机将自己附加到后端调用 url。

在 url 之前 **私人url =“http://localhost:3000/api/v1”;** 在那种情况下 angular 可以很好地连接到后端。 但现在我不知道它是如何在 start

中附加 angular locahost url

请帮忙

您需要向服务提供完全合格的 url,否则 angular 将尝试做相对 url。

将 url 变量更改为

private url = "http://api.angularapp.site/api/v1";

一切正常。