【发布时间】:2017-04-12 23:58:52
【问题描述】:
当使用 HTTP GET 访问我的 Cloudant/NoSQL 数据库时,我目前收到 Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin. 错误。
我知道设置 Access-Control-Allow-Origin: * 将允许来自 localhost 的 GET 请求,但是我没有看到 Angular 2 专门用于设置标头的文档。
async getData(): Promise<IPost[]> {
return this._http.get(this._postUrl)
.toPromise()
.then(this.extractData)
.catch(this.handleError);
}
IPost[] 是执行extractData() 后将返回的对象。
感谢您的帮助,感谢您的宝贵时间!
【问题讨论】:
-
您需要在服务器上设置此标头,而不是在 Angular 应用程序中。
-
找到了,隐藏在数据库的设置深处。谢谢!
标签: angular get promise http-headers observable