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.

最新文章

  1. 【NFC】Android NFC API Reference中英文
  2. 开源(免费)三维 GIS(地形,游戏)
  3. CocoaPods的安装及使用/利用开源库Diplomat实现分享及第三方登录/git的使用
  4. TOMCAT 关闭报错:Tomcat did not stop in time. PID file was not removed
  5. 论文阅读之 DECOLOR: Moving Object Detection by Detecting Contiguous Outliers in the Low-Rank Representation
  6. Python cookbook-读书笔记01
  7. 不用安装语言包,教你将PS界面语言修改成默认语言(英语)
  8. freemaker遍历嵌套list的map
  9. Spring源代码由浅入深系列五 GetBean
  10. RHEL6.4 NFS文件共享服务搭建
  11. Java的static详解
  12. Ubuntu9.04更新源
  13. 阅读MDN文档之基本盒模型(三)
  14. JS事件捕获和事件冒泡
  15. shell 处理小数位加减法(比较)运算
  16. java无需解压zip压缩包直接读取包内的文件名(含中文)
  17. Port Channel and VPC
  18. luogu P3197 [HNOI2008]越狱
  19. labeled statement:标签语句
  20. MySQL 分支和循环结构

热门文章

  1. 转 EL表达式
  2. js中Object.defineProperties 定义一个在原对象可读可写的方法
  3. Gym 100952 H. Special Palindrome
  4. POJ 题目1145/UVA题目112 Tree Summing(二叉树遍历)
  5. 1.Node.js
  6. 2.4 Connect API官网剖析(博主推荐)
  7. 如何应对DDOS网络攻击(之二)
  8. 洛谷 P2655 2038年问题
  9. GraphX 图数据建模和存储
  10. Android LruCache类分析