【发布时间】:2020-08-12 08:45:45
【问题描述】:
我已经构建了一个 Angular 服务,它负责从 REST 端点检索数据。 它有效,但我需要知道是否
- 还有其他方法吗?
- 更重要的是。如果有,哪种方式是正确的?
感谢您的帮助。
这是我的代码:
@Injectable()
export class XXXService {
private static ENDPOINT = "./api/XXX/YYY/rate";
constructor(private http: HttpClient) {
}
public getRateDatas(): Observable<IRate[]> {
const httpParams = new HttpParams()
.set('paramId', 's1')
.set('paramCode', 'r1')
.set('paramNumber', '2');
return this.http.get<IRate[]>(XXXService.ENDPOINT, {params: httpParams});
}
}
【问题讨论】:
-
使用
httpClient将是您最好的选择。供参考:angular.io/guide/http