ใช้ HttpClient
ดีกว่า Http
Use the HttpClient
class from HttpClientModule
if you’re using Angular 4.3.x and above:
1 2 3 4 5 6 7 8 9 10 11 |
import { HttpClientModule } from '@angular/common/http'; @NgModule({ imports: [ BrowserModule, HttpClientModule ], ... class MyService() { constructor(http: HttpClient) {...} |
It’s an upgraded version of http
from @angular/http
module with the following improvements:
- Interceptors allow middleware logic to be inserted into the pipeline
- Immutable request/response objects
- Progress events for both request upload and response download
Link