I want to migrate my angular project from angular 5 to angular 7 and for that, I want to convert my all HTTP calls to httpclient call.
Asked
Active
Viewed 44 times
-1
-
5I will keep my fingers crossed for you! – Antoniossss May 13 '19 at 11:13
-
4Please check https://angular.io/guide/http as a general HttpClient documentation. Also check Stack Overflow FAQ https://stackoverflow.com/help/how-to-ask – ssuperczynski May 13 '19 at 11:14
-
2What are you waiting for, go ahead and start converting FTW! – ViqMontana May 13 '19 at 11:43
-
2Welcome to SO. Please take the time to read [ask]. It will help you craft solid questions that will hopefully get useful answers. In this question, you haven't demonstrated what you've tried to fix your problem. – orde May 15 '19 at 01:55
1 Answers
-1
Could you plz, write code. Or give a codesandbox - example. You could use interceptor, for default header.
some example
getPrices(country: string, items: string, currency: string = ''): Observable<any> {
const params = new HttpParams()
.set('country', country.toUpperCase())
.set('items', items)
.set('currency', currency.toUpperCase());
return this.customHttpHandler.request('GET',
`${ this.priceApiUrl }/example`,
new PriceInterceptor(this.exampleService),
{
params
}
).pipe(
catchError(() => of([])),
retry(2),
timeout(50000)
);
}
One more example:
export class HttpService{
constructor(private http: HttpClient){ }
//http://localhost:60489/Home/PostUser ASP.NET MVC
//http://localhost:8080/angular/setUser.php PHP
// http://localhost:60820/api/post
postData(user: User){
const myHeaders = new HttpHeaders().set('Authorization', 'my-auth-token'),;
return this.http.post('http://localhost:60820/api/values', user, {headers:myHeaders});
}
}

NoName
- 183
- 10