前言
- 由于之前對Rxjs的Observable不熟悉,舊的HttpService使用Promise,經過學習發現Rxjs相對Promise強大很多,遂統一使用Rxjs
Promise 對比 Observable
- 可以看這里也可以看這里
- 大漠窮秋的視頻-服務端通訊與RxJS,總結了以下三點
代碼
使用
- 以前是構造函數注入Angular Http,現在注入HttpService,然后調用對應方法就行了
//使用前
constructor(public http: Http) {
}
//使用后
constructor(public http: HttpService) {
}