[AngularFire 2 ] Hello World - How To Write your First Query using AngularFire 2 List Observables ?
2024-08-25 16:21:28
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, ))
)
} }
firebase database.list() method return 'FirebaseListObservable' type.
最新文章
- 【NFC】Android NFC API Reference中英文
- 开源(免费)三维 GIS(地形,游戏)
- CocoaPods的安装及使用/利用开源库Diplomat实现分享及第三方登录/git的使用
- TOMCAT 关闭报错:Tomcat did not stop in time. PID file was not removed
- 论文阅读之 DECOLOR: Moving Object Detection by Detecting Contiguous Outliers in the Low-Rank Representation
- Python cookbook-读书笔记01
- 不用安装语言包,教你将PS界面语言修改成默认语言(英语)
- freemaker遍历嵌套list的map
- Spring源代码由浅入深系列五 GetBean
- RHEL6.4 NFS文件共享服务搭建
- Java的static详解
- Ubuntu9.04更新源
- 阅读MDN文档之基本盒模型(三)
- JS事件捕获和事件冒泡
- shell 处理小数位加减法(比较)运算
- java无需解压zip压缩包直接读取包内的文件名(含中文)
- Port Channel and VPC
- luogu P3197 [HNOI2008]越狱
- labeled statement:标签语句
- MySQL 分支和循环结构