angular - 类型承诺上不存在属性映射
问题描述
在我的 Angular 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 就像 from(http.post().then()) 一样,它返回一个 observable 以便你可以管道流
推荐阅读
- heroku - 网站不是从 WiFi 加载,而是来自移动数据 - 我的 IP 是否被阻止?
- angular - 如何在同一组件上切换标题?
- javascript - 如何在没有猫鼬的情况下使用 mongodb 获取 ObjectIds 数组的值
- android - 将 onSaveInstanceState 与 Viewmodel 一起使用时无法创建类的实例
- elasticsearch - 弹性搜索/休眠搜索:如何在 java 中使用查询 DSL API 编写 xor 运算符?
- nosql - 如何从 restdb.io 获取唯一记录?
- javascript - 如何停止执行包含 useState 的命令?
- python - 无法为 Python 3.8.5 安装 mysql 连接器
- python - 在 python 中创建一个函数,它将在 pandas 数据框中估算均值或中值
- airflow - 超过“dagrun_timeout”时触发“on_failure_callback”的气流