angular - 从 Angular7 调用 Firebase 函数时出错:响应不是有效的 JSON 对象
问题描述
我尝试在角度应用程序中使用 firebase 函数。我使用 angularfire2 库结果:
{err:错误:响应不是有效的 JSON 对象。在新的 HttpsErrorImpl ( http://localhost:4200/vendor.j ...}
const functions = require('firebase-functions');
const cors = require('cors')({
origin: true
});
exports.helloWorld = functions.https.onRequest((request, response) => {
cors(request, response, () => {
response.send('Hello from Firebase!');
});
});
import { Component, OnInit } from '@angular/core';
import { AngularFireFunctions } from 'angularfire2/functions';
import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
message: Observable<string>;
message2: string;
constructor(private fns: AngularFireFunctions) {
}
ngOnInit() {
}
getfsf() {
this.fns.httpsCallable('helloWorld')({ text: 'Some Request Data' })
.pipe(first())
.subscribe(resp => {
console.log({ resp });
}, err => {
console.error({ err });
});
}
}
解决方案
这就是我能够修复它的方式。
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send({ "data": "Hello from Firebase!" });
})
我们需要这样做很奇怪,但它确实有效!
推荐阅读
- function - 如何在 kotlin 的内部函数中从顶级函数返回?
- c# - 在“代码隐藏”中将 WPF ListView 列居中
- python - Python:条件表达式中的替换表达式
- java - 注入一个填充在不同类中的bean
- ios - Firebase 存储拒绝图像删除请求:错误域=FIRStorageErrorDomain 代码=-13021“用户没有访问权限”
- java - 用于简单访问的 JPA JOIN
- latex - Latex Beamer:仅显示帧中的覆盖子集
- sql - OPENQUERY 中无法识别数值错误
- python - 按状态汇总的 Pandas 值计数
- javascript - 如何使用另一个嵌套对象更新嵌套对象?