[英]property map does not exist on type promise<void>
In my angular 6 project am getting property map does not exist on type promise error even I included 在我的angular 6项目中,即使我包含了,但类型承诺错误也不存在属性映射
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
Following is my code 以下是我的代码
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)
}
After some google I found solution like below but that is also not working 经过一些谷歌,我发现下面的解决方案,但也无法正常工作
import { map } from 'rxjs/operators';
pipe(map((response: Response) => response.json()))
After including this it shows error property type does not exist on type promise Following is my custom post
method 包含此内容后,它表明诺言类型上不存在错误属性类型,这是我的自定义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,例如from(http.post()。then()),它返回一个可观察的对象,以便您可以通过管道传输流
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.