未从 angular 调用 Web API

Web API not being called from angular

我正在尝试在 angular 中调用自定义 API,但由于某些原因它没有调用它。在此之前,我在 angular(在 _api.service.ts)中创建了 10 个以相同方式调用 web API 的函数,它们是正确的,我的 web API 被调用并返回了数据, 一切都是好的。然后我在 web API 中又做了一个方法,在 angular 中又做了一个组件(其中调用了函数 getList() ),但没有用,从未调用过 API 。

getList(id: string, chosen: string): Observable<StopListModel[]> {
        let myUrl: string = API_URL + '/stop/list';
        myUrl += '/' + id;
        myUrl += '/' + chosen;
        //debugger goes to this line, url is correct but API not called
        return this.http.get<StopListModel[]>(myUrl, this.httpUtils.getHTTPHeader());
   }

当我调试时,我看到 API 的 url 是从 angular 正确发送的,就像在我的项目中成功调用 API 的其他 10 个函数一样,所以我认为我不需要从我的网站 API 向您发送代码。我很困惑,所以我将调用 getList() 的行从新组件移动到现有组件,我已经知道我的 _api.service 将成功调用 web API 因为在该组件中有一个函数(对于例如 getUsers() ) 正确调用 API。它没有用,getList() 没有调用 API。

我假设 getList() 的 web API 有问题,但为了确保在第二个组件中我调用了另一个 _api.service 函数(从另一个组件调用时可以工作) ,令人惊讶的是 - API 也没有为该函数调用。

然后我看到了我认为的问题:当我尝试在我的组件的 any 中调用 any 函数时,所有这些“新”函数从不调用 API,只调用已经存在的旧函数,即使它们在自己的组件中正确工作。

export class DetaljiStopoviComponent{
            stops$: Observable<StopStatisticsModel[]>;
            list$: Observable<StopListModel[]>
            constructor(
              private apiService: APIService,
              route: ActivatedRoute
            ) {
                var id = route.snapshot.params['id'];
                this.stops$ = this.apiService.getStopStatistics(id); //this works, it was there before - but any other calling I add under this, API is not called (this is the case for every component, every function)
                this.list$ = this.apiService.getList(id, '3'); //this is the newest one, I can't make it call API even in the empty components      
            }
}

我很困惑,也没有经验angular,我很好奇问题是什么。我不认为网络 API 有什么问题,但我不确定。有人有什么建议吗?

我认为这是语法问题,对于 get 方法试试这个

return this.http.get<StopListModel[]>(myUrl, {headers:this.httpUtils.getHTTPHeader()});

您似乎忘记订阅了:

this.stops$ = this.apiService.getStopStatistics(id);
this.list$ = this.apiService.getList(id, '3');   

我认为 this.stops$ 适合你,因为在模板中的某处你有异步管道 (stops$ | async)。

所以尝试做:

this.list$.subscribe(response => console.log(response));

之后应该发送请求