Ionic - 运行时错误 this.fba.logEvent(...).then 不是函数
Ionic - Runtime Error this.fba.logEvent(...).then is not a function
我正在使用 Ionic 和 Firebase。我已经创建了 firebase 项目,单击 "add fire to your android app" 图标并按照步骤操作。
关注。是我的 html 页面上的代码:
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
Firebase Analytics
<p>
Click the button to log a custom event
</p>
<button ion-button full (click)="logClick()">Log event</button>
</ion-content>
以下代码在本页的ts中:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { EventLoggerProvider } from '../../providers/event-logger/event-logger';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController,
public logger: EventLoggerProvider) {
}
logClick() {
this.logger.logButton('homeButton',{ pram: "paramValue" })
}
}
关注。代码在提供商中:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { FirebaseAnalytics } from '@ionic-native/firebase-analytics';
@Injectable()
export class EventLoggerProvider {
constructor(public fba: FirebaseAnalytics) {
console.log('Hello EventLoggerProvider Provider');
}
logButton(name:string,value:any){
this.fba.logEvent(name, { pram:value })
.then((res: any) => {console.log(res);})
.catch((error: any) => console.error(error));
}
}
我 运行 "ionic cordova run android" 并在移动设备上启动了该应用程序,一切似乎都正常。但是,当我执行 "ionic serve" 时,页面在浏览器中加载正常,但是当我单击该按钮时,可能是什么原因导致它执行以下操作。错误?
Ionic - Runtime Error this.fba.logEvent(...).then is not a function
看到代码就更清楚了
import { FirebaseAnalytics } from '@ionic-native/firebase-analytics';
@ionic-native
函数仅适用于真机或模拟器。否则会报错。
我正在使用 Ionic 和 Firebase。我已经创建了 firebase 项目,单击 "add fire to your android app" 图标并按照步骤操作。
关注。是我的 html 页面上的代码:
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
Firebase Analytics
<p>
Click the button to log a custom event
</p>
<button ion-button full (click)="logClick()">Log event</button>
</ion-content>
以下代码在本页的ts中:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { EventLoggerProvider } from '../../providers/event-logger/event-logger';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController,
public logger: EventLoggerProvider) {
}
logClick() {
this.logger.logButton('homeButton',{ pram: "paramValue" })
}
}
关注。代码在提供商中:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { FirebaseAnalytics } from '@ionic-native/firebase-analytics';
@Injectable()
export class EventLoggerProvider {
constructor(public fba: FirebaseAnalytics) {
console.log('Hello EventLoggerProvider Provider');
}
logButton(name:string,value:any){
this.fba.logEvent(name, { pram:value })
.then((res: any) => {console.log(res);})
.catch((error: any) => console.error(error));
}
}
我 运行 "ionic cordova run android" 并在移动设备上启动了该应用程序,一切似乎都正常。但是,当我执行 "ionic serve" 时,页面在浏览器中加载正常,但是当我单击该按钮时,可能是什么原因导致它执行以下操作。错误?
Ionic - Runtime Error this.fba.logEvent(...).then is not a function
看到代码就更清楚了
import { FirebaseAnalytics } from '@ionic-native/firebase-analytics';
@ionic-native
函数仅适用于真机或模拟器。否则会报错。