[Angular 2] Get start with Firebase

Source: Internet
Author: User


Create a Firebase Servcie:

Import {injectable} from 'Angular2/core'; import {Http, Response} from 'angular2/http'; @Injectable () Exportclassfirebaseservice{Constructor (Private_http:http) {} addonehistory (keyword:string){        ConstBODY =json.stringify ({keyword:keyword}); return  This. _http.post ('Https://xxx.com/searchHistory.json', body). Map ((res:response)= {                returnRes.json ();    }); } gethistories () {return  This. _http.Get('Https://xxxx/searchHistory.json'). Map ((res:response)={                returnRes.json (); }). Map ((hobj)= {                returnObject.keys (hobj). Map (Key)={                        returnHobj[key];            }); })    }}

Display the list:

Import {Component, OnInit, Input} from 'Angular2/core'; import {Firebaseservice} from './firebaseservice'; @Component ({selector:' History', Template: '<ul><li *ngfor="#item of Histories | Async">{{Item?. Keyword}}</li></ul>`}) ExportclassHistroycomponent implements OnInit {histories; Constructor (Private_firebaseservice:firebaseservice) {} ngoninit () { This. Histories = This. _firebaseservice.gethistories (); }}

[Angular 2] Get start with Firebase

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: