我正在使用Firebase处理angular2seedadvanced。在我的组件中使用Firebase服务时,它无法正常工作。如何在angular2seedadvanced中的组件内使用服务。我正在关注
我在这里附上我的代码文件。
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不是一个函数。
我该怎么办?我该如何解决这个问题。提前谢谢。
答案 0 :(得分:0)
如果您没有安装打字,那么TypeScript转换程序会认为这是一个错误。
尝试在map
文件中为firebase添加一个输入条目:
typings.json
然后打开控制台窗口并输入"firebase": "registry:dt/firebase#2.4.1+20160412125105",
。
供参考: https://github.com/ChuckkNorris/SkillPath/blob/master/typings.json