在我的角度6项目我得到属性地图不存在类型承诺错误,即使我包括
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
以下是我的代码
submit(): Promise<any> {
return http.post('api/SubmitEmployee', JSON.stringify(this.formData))
.map((response: Response) => <any>response.json())
.toPromise()
.catch(this.handlePromiseError)
}
handlePromiseError(error: Response) {
console.log(error)
}
在谷歌之后,我找到了类似下面的解决方案,但这也无效
import { map } from 'rxjs/operators';
pipe(map((response: Response) => response.json()))
包含此之后,它显示错误属性类型在类型promise上不存在以下是我的自定义post
方法
post(url: string, content: any, resolve: ResolveFunction = null, reject: RejectFunction = null) {
this.clearCache();
const retryFunc = _ => this.post(url, content, resolve, reject);
return fetch(appSettings.baseApiUri + url, {
method: 'POST',
headers: this.getCustomHeader(),
body: content
})
.then(result => {
this.handleResponse(url, result, retryFunc, resolve, reject);
})
.catch(error =>
this.debounce(_ => this.handleError(url, error, retryFunc).catch(_ => reject(error)), this.debounceTimeout)
);
}
使用from来包装http.post,如(http.post()。then()),它返回一个observable,以便你可以管道流