Parse date with Angular 4.3 HttpClient

后端 未结 5 928
再見小時候
再見小時候 2020-12-14 01:20

I\'m currently switching to the new HttpClient of Angular 4.3. One advantage is that I can specify a type info on the GET method and that the returned JSON is parsed into th

5条回答
  •  孤城傲影
    2020-12-14 01:47

    You still can, but you need to import the map()-operator from rxjs like this:

    import 'rxjs/add/operator/map';
    

    Then you can, just as Diego pointed out, use the map like this:

    return this.http.get(url)
    .map(x => {
    x.published = new Date(String(x.published));
        return x;
    })
    [...]
    

提交回复
热议问题