我正在使用 Firebase 开发 angular2seedadvanced。在我的组件中使用 Firebase 服务时,它不起作用。如何在 angular2seedadvanced 中使用组件内部的服务。我正在关注
- https://github.com/jlooper/pocketrave
- https://github.com/NathanWalker/angular-seed-advanced/wiki/How-to-integrate-Firebase-across-all-platforms-(web-nativescript-desktop)。
在这里我附上我的代码文件。
firebase.service.ts
import { Injectable, Inject, NgZone } from '@angular/core';
import { FIREBASE } from '../../demoapp/index';
@Injectable()
export class DatabaseService {
private database: any;
private onSync: Function;
private userID: string;
constructor( @Inject(FIREBASE) firebase: any, private ngZone: NgZone) {
console.log('Constructing DatabaseService');
// Initialize Firebase
var config = {
// your web config from Firebase console
apiKey: "",
authDomain: "",
databaseURL: "",
storageBucket: ""
};
firebase.initializeApp(config);
this.database = firebase.database();
};
public authenticate() {
};
login.component.ts
import { Store } from '@ngrx/store';
import { BaseComponent } from '../../frameworks/core/index';
import { DatabaseService } from '../../frameworks/demoapp/services/database.service';
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'demo-login',
providers: [DatabaseService],
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent {
constructor(private databaseService: DatabaseService) {
}
login() {
this.databaseService.authenticate();
}
}
收到错误
this.databaseService.authenticate 不是函数。
我应该怎么办?我该如何解决这个问题。提前致谢。