<分区>
我在我的 ionic 应用程序中使用 Angular 5。我正在尝试从我的代码中调用端点
ngOnInit(): void {
//Called after the constructor, initializing input properties, and the first call to ngOnChanges.
//Add 'implements OnInit' to the class.
this.httpClient.get('https://abc-66b76.cloudfunctions.net/getBillNo', {
headers: {
'Access-Control-Allow-Origin': '*'
}
}).subscribe(data => {
console.log('firebase bill No: ', data);
this.bill.billNo = data.billNo;
})
}
当我的页面加载上面的代码时,在 chrome 浏览器控制台中我得到以下错误:
Failed to load https://abc-66b76.cloudfunctions.net/getBillNo: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.
但是,如果我在我的 chrome 浏览器中检查我的网络选项卡,我可以看到它已经访问了服务器并得到了响应。
谁能帮我解决这个问题。
My Backend is firebase functions.