首页 > 代码库 > [AngularFire 2 ] Hello World - How To Write your First Query using AngularFire 2 List Observables ?
[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.
[AngularFire 2 ] Hello World - How To Write your First Query using AngularFire 2 List Observables ?
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。