localhost 以角度方式将自身附加在后端 api 之前

Shu*_*haw 6 http mean mean-stack angular

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

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

我该如何解决这个问题。

后端网址: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

Run Code Online (Sandbox Code Playgroud)

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

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

为什么这个 localhost 将自身附加到后端调用 url。

在 url 之前 ** private url = " http://localhost:3000/api/v1 ";** 在这种情况下,角度可以很好地连接到后端。但现在我不明白它是如何在启动中附加角度 locahost url

请帮忙

The*_*bio 10

您需要向服务提供完整的合格 URL,否则 Angular 将尝试执行相对 URL。

将 url 变量更改为

private url = "http://api.angularapp.site/api/v1";
Run Code Online (Sandbox Code Playgroud)

一切都应该有效。