如何在angular2seed中使用服务



我正在使用Firebase开发angular2seedadvanced。在我的组件内使用Firebase服务时,它不工作。如何在angular2seedadvanced的组件中使用service ?I am following

  • 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不是一个函数。

我该怎么办?我该如何解决这个问题?

如果你没有安装这些类型,TypeScript转译器会认为这是一个错误。

尝试在您的typings.json文件中为firebase添加一个类型条目:

"firebase": "registry:dt/firebase#2.4.1+20160412125105",

然后打开控制台窗口并输入typings install

供参考:https://github.com/ChuckkNorris/SkillPath/blob/master/typings.json

最新更新