最终如何在HttpClient Angular 7中使用

时间:2018-11-15 01:34:02

标签: angular httpclient angular-http angular-httpclient finally

在以前的Angular版本中,我使用finally()就像下面的代码一样

constructor(
    private http: Http
) { }

const headers = new Headers({ 'Authorization': this.authenticate.getToken(), 'Content-Type': 'application/json' });
const options = new RequestOptions({ headers: headers });

return this.http.put(Globals.SERVER_URL + '/alert/exempted?_id=' + alertId + '&isExempted=' + status + '&app_id=' + app_id, options )
                .map(this.extractData)
                .catch(this.handleError)
                .finally(() => {
                    this.exceptionSubject.next();
});

但是现在当使用Angular 7时,我不能再使用它了。最后如何在代码中插入(HttpClient)?这是我现有的代码:

constructor(
    private http: HttpClient
) { }

const header = new HttpHeaders({'Content-Type': 'application/json'}); 
return this.http.get(Globals.ATTENDANCE_URL + '/individual_employment_setting/detail/' + id, { headers: header })
        .pipe(tap(resp => {
            if (resp['success'] === true) {
                localStorage.setItem('settings', JSON.stringify(resp['data']));
            }
        }
));

0 个答案:

没有答案