博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Angular 2] Get start with Firebase
阅读量:7127 次
发布时间:2019-06-28

本文共 1245 字,大约阅读时间需要 4 分钟。

Create a Firebase Servcie:

import {Injectable} from 'angular2/core';import {Http, Response} from 'angular2/http';@Injectable()export class FirebaseService{    constructor(private _http: Http){    }    addOneHistory(keyword: string){        const body = JSON.stringify({keyword: keyword});        return this._http.post('https://xxx.com/searchHistory.json', body)            .map( (res: Response) => {                return res.json();            });    }    getHistories(){        return this._http.get('https://xxxx/searchHistory.json')            .map( (res: Response)=>{                return res.json();            })            .map( (hObj) => {                return Object.keys(hObj)                    .map( (key)=>{                        return hObj[key];                    });            })    }}

 

Display the list:

import {Component, OnInit, Input} from 'angular2/core';import {FirebaseService} from './FirebaseService';@Component({    selector: 'history',    template: `
  • {
    {item?.keyword}}
`})export class HistroyComponent implements OnInit { histories; constructor(private _fireBaseService:FirebaseService) { } ngOnInit() { this.histories = this._fireBaseService.getHistories(); }}

 

转载地址:http://eghel.baihongyu.com/

你可能感兴趣的文章
为什么要做IT监控?
查看>>
java泛型
查看>>
8大排序算法图文讲解
查看>>
架构师是什么,做什么
查看>>
2019-5-8时代的变迁
查看>>
neutron-metadata-proxy无响应,导致windos2003密码透传失败
查看>>
用Python实现用户登录接口
查看>>
毕业前1个月的想法
查看>>
例程详析动态链接库
查看>>
geopy使用详解
查看>>
Notebook Workflows: The Easiest Way to Implement Apache Spark Pipelines
查看>>
mysql必知必会表样例
查看>>
我的友情链接
查看>>
python logging 模块在windows报错ConfigParser.NoSectionError: No section
查看>>
windows下python3虚拟环境搭建
查看>>
error at ::0 formal unbound in pointcut
查看>>
关于linux下Squid透明代理的试验
查看>>
马哥2016全新Linux+Python高端运维班第四期-第三次作业
查看>>
AngularJS基础语法
查看>>
程序编译过程
查看>>