【发布时间】:2020-07-11 16:39:46
【问题描述】:
我有一项服务,我对我的 API 执行 http 请求,然后我为其他目的提供服务,将 url 传递给 http 请求服务。但是当我尝试将模型添加到我的 get 请求时,我收到了 Expected 0 type arguments, but got 1 错误。
calendar.service.ts
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
// WebReq for http requests
import { WebRequestService } from './web-request.service';
import { ICalendarEvent } from '../../models/calendar-event.model';
@Injectable({
providedIn: 'root',
})
export class CalendarService {
constructor(private webReqService: WebRequestService) { }
// Where I get the error
getCalendarEvent(): Observable<ICalendarEvent[]> {
return this.webReqService.get<ICalendarEvent[]>('/calendars');
}
}
web-request.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class WebRequestService {
readonly _url: string;
constructor(private http: HttpClient) {
this._url = 'some url';
}
get(uri: string) {
return this.http.get(`${this._url}/${uri}`);
}
post(uri: string, payload: Object) {
return this.http.post(`${this._url}/${uri}`, payload);
}
patch(uri: string, payload: Object) {
return this.http.patch(`${this._url}/${uri}`, payload);
}
delete(uri: string) {
return this.http.delete(`${this._url}/${uri}`);
}
}
日历事件.model.ts
export interface ICalendarEvent {
id: number;
start: string;
end: string;
title: string;
estimate_number: string;
brand: string;
meters: string;
floor: string;
floor_type: string;
plint_type: string;
floor_installer: number;
city: string;
street: string;
postal_code: string;
province: string;
notes: string;
}
【问题讨论】:
标签: angular typescript api rxjs observable