Angular 4, convert http response observable to object observable

后端 未结 3 631
没有蜡笔的小新
没有蜡笔的小新 2021-02-02 01:20

I\'m new to the concepts of observables and need some help with a conversion.
I have a service which returns an Observable from a Http request,

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-02 01:39

    As of angular 4.3 this can be done automatically.

    Example:

    export class SomeService {
        constructor(private http: HttpClient) {}  // <--- NOTE: HttpClient instead of Http
    
        getSome(): Observable {
            return this.http.get('myUrl');
        }
    }
    

    So in your case that would be:

    return this.http.post(Constants.WEBSERVICE_ADDRESS + "/priceTag", null, {headers: headers});

    Again, use the HttpClient instead of Http

提交回复
热议问题