首页 > 其他 > 详细

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

时间:2016-10-03 19:33:27      阅读:320      评论:0      收藏:0      [点我收藏+]

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.

 

技术分享

 

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

原文:http://www.cnblogs.com/Answer1215/p/5929469.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!