我正在使用@angular/fire
并尝试调用简单的callable
。
按照firebase.google.com/docs和angularfire/functions docs上的指南进行设置:
app.module.ts
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
AngularFireModule.initializeApp(environment.firebase),
AngularFireFunctionsModule,
],
providers: [
{ provide: ORIGIN, useValue: 'https://project-id-beta.web.app/' }
],
bootstrap: [AppComponent],
})
export class AppModule {}
app.component.ts
import { AngularFireFunctions } from '@angular/fire/functions'
import { Component } from '@angular/core'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
constructor(private fns: AngularFireFunctions) {
this.callTestFunction();
}
callTestFunction() {
const callable = this.fns.httpsCallable('testfunction');
const observable = callable({ name: 'My Name'});
observable.subscribe(console.log, console.error);
}
}
Firebase Cloud功能
import { https } from 'firebase-functions';
const _testfunction,
= (data: { name: string }, context: https.CallableContext) => {
return { message: `⚡ name: ${data.name}` }
};
export const testfunction = https.onCall(_testfunction);
在浏览器控制台中出现以下错误:
Subscriber.js:183 Error: Response is not valid JSON object.
at new HttpsErrorImpl (index.cjs.js:58)
at Service.<anonymous> (index.cjs.js:543)
at step (tslib.es6.js:100)
at Object.next (tslib.es6.js:81)
at fulfilled (tslib.es6.js:71)
at ZoneDelegate.invoke (zone-evergreen.js:364)
at Zone.run (zone-evergreen.js:123)
at zone-evergreen.js:857
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Zone.runTask (zone-evergreen.js:167)
{
"name": "testfunctions",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~9.1.0",
"@angular/common": "~9.1.0",
"@angular/compiler": "~9.1.0",
"@angular/core": "~9.1.0",
"@angular/fire": "^6.0.0",
"@angular/forms": "~9.1.0",
"@angular/platform-browser": "~9.1.0",
"@angular/platform-browser-dynamic": "~9.1.0",
"@angular/router": "~9.1.0",
"firebase": "^7.14.3",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.901.0",
"@angular/cli": "~9.1.0",
"@angular/compiler-cli": "~9.1.0",
"@angular/language-service": "~9.1.0",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.4.1",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~3.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.8.3",
"@angular-devkit/architect": "~0.900",
"firebase-tools": "^8.0.0",
"fuzzy": "^0.1.3",
"inquirer": "^6.2.2",
"inquirer-autocomplete-prompt": "^1.0.1"
}
}
该解决方案必须是一个简单的解决方案,因为它是最基本的可调用呼叫,但是我还不能弄清楚。 你有什么建议吗?
非常感谢