已连接Firebase,但无法在其他文件中使用它。需要知道如何访问并显示Firebase内容。
文件系统: src->应用程序->主页
app module.ts:
export class AppModule {}
var config = {
apiKey: "AIzaSyBvJ0ZWfd2GcIpKgdcIaZKJ6ohLW_E7DOs",
authDomain: "fir-storage-login.firebaseapp.com",
databaseURL: "https://fir-storage-login.firebaseio.com",
projectId: "firebase-storage-login",
storageBucket: "firebase-storage-login.appspot.com",
messagingSenderId: "803036592201"
};
var app = firebase.initializeApp(config);
var database = firebase.database(app);
home.page.html
<ion-content>
<ion-searchbar (ionInput)="getStations($event)"></ion-searchbar>
<ion-list>
<ion-item *ngFor="let station of stations">
{{ station }}
</ion-item>
</ion-list>
</ion-content>
home.page.ts
import * as firebase from 'firebase/app';
import { AppModule } from '../app.module';
states: Array<any>;
initializeStates(){
return firebase.database().ref('States').once('value').then(snapshot =`>
snapshot.val());{
this.states }