[AngularFire 2 ] Hello World - How To Write your First Query using AngularFire 2 List Observables ?

In this lesson we are going to use AngularFire 2 for the first time. We are going to configure the AngularFire 2 module, inject the AngularFire service in our service layer and use it do our first Firebase query: we are going to retrieve a list of objects from the database.

 

Install:

//install 

npm install --save angularfire2

 

Import AngularFireModule in app.module.ts:

...
import {firebaseConfig} from "../environments/firebase.config";
import {AngularFireModule} from "angularfire2";

@NgModule({
  ...
  imports: [
    ...
    AngularFireModule.initializeApp(firebaseConfig)
  ],

 

Load the data in service: realtime.service.ts:

import { Injectable } from '@angular/core';
import {AngularFire, FirebaseListObservable} from "angularfire2";

@Injectable()
export class RealtimeService {

  constructor(private af: AngularFire) {
    const courses$: FirebaseListObservable<any> = af.database.list('courses');
    courses$.subscribe(
      val => console.log("val", JSON.stringify(val, null, 2))
    )
  }

}

firebase database.list() method return 'FirebaseListObservable' type.

 

 

转载于:https://www.cnblogs.com/Answer1215/p/5929469.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值