Angular2服务传递错误的网址

时间:2017-03-25 18:43:53

标签: javascript angular asp.net-core

我正在使用Angular2 + .Net Core,并尝试使用两个不同的API网址调用两次相同的服务功能。

我的功能:

app.service.ts

getRequests(url: string): Observable<Model> {
    return this.http.get(url, { withCredentials: true })
        .map((res: Response) => res.json())
        .catch((res: Response) => this.handleError(res));
}

home.component.ts

this.AppService.getRequests('url/to/first/api').subscribe(res => {
    console.log(res)
});

this.AppService.getRequests("another/url/to/second/api").subscribe(res => {
    console.log(res);
});

结果是浏览器在第一个网址上发送了两个请求(完全忽略了不同的网址)

我在Angular2中很新,我不确定它是产品缺陷还是我滥用Angular服务。

我试图用其他名称复制这个函数(第二个url),但结果更糟糕(更糟)。 应用程序抛出了this.AppService.getRequestsCopy is not a function

的错误

更新

问题是app.service.js不会追加app.service.ts中所做的更改。必须找出原因。

1 个答案:

答案 0 :(得分:0)

我从我的解决方案中删除了app.service.js和app.service.js.map,一切正常。