zoukankan      html  css  js  c++  java
  • [AngularFire 2 ] Hello World

    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.

  • 相关阅读:
    PhoneGap 数据库操作
    eclipse打开html文件
    Android 播放音频
    本地搭建 Apache 服务器
    C# CSV 导出
    .NET中使用MySQL数据库
    搭建一个phonegap环境,用eclipse+phonegap
    js test()
    Dom指针函数
    Js 禁用输入法 imemode 全角转换成半角
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5929469.html
Copyright © 2011-2022 走看看