【问题标题】:localhost appending itself before the backend api in angularlocalhost 在 Angular 后端 api 之前附加自身
【发布时间】:2020-02-24 10:36:51
【问题描述】:

我已将我的后端放到 aws 中。后端网址在邮递员中工作正常。

但是当我将我的后端 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

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

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

为什么这个 localhost 会附加到后端调用 url。

在网址之前 ** 私人网址 = "http://localhost:3000/api/v1";** 在那种情况下,角度很好地连接到后端。 但现在我不知道它是如何在 start 中附加 angular locahost url

请帮忙

【问题讨论】:

    标签: angular http mean-stack mean


    【解决方案1】:

    你需要为服务提供一个完整的限定url,否则angular会尝试做一个相对url。

    将url变量改为

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

    一切都应该工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-09
      • 2020-05-17
      • 2017-05-09
      • 2020-02-23
      • 1970-01-01
      • 2019-09-22
      • 2021-05-30
      • 1970-01-01
      相关资源
      最近更新 更多