Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
  3.  
  4. @Injectable()
  5. export class FirebaseService {
  6.  
  7. listings: FirebaseListObservable<any[]>;
  8.  
  9. constructor(private af: AngularFireDatabase) {}
  10.  
  11. getListings(){
  12. console.log('In getListings');
  13. this.listings = this.af.list('/listings') as FirebaseListObservable<Listing[]>;
  14. return this.listings;
  15. }
  16.  
  17. }
  18.  
  19. interface Listing{
  20. $key?:string;
  21. title?:string;
  22. type?:string;
  23. image?:string;
  24. city?:string;
  25. owner?:string;
  26. bedrooms?:string;
  27. }
  28.  
  29. import { Component, OnInit } from '@angular/core';
  30. import { FirebaseService } from '../../services/firebase.service';
  31.  
  32. @Component({
  33. selector: 'app-listings',
  34. templateUrl: './listings.component.html',
  35. styleUrls: ['./listings.component.css']
  36. })
  37. export class ListingsComponent implements OnInit {
  38. listings:any;
  39.  
  40. constructor(private firebaseService:FirebaseService) { }
  41.  
  42. ngOnInit() {
  43. this.firebaseService.getListings().subscribe(listings => {
  44. console.log(listings);
  45. this.listings = listings;
  46. });
  47. }
  48.  
  49. }
  50.  
  51.  
  52. I am able to login using Google authentication and then when I try to call the getListing method in Service, I don't get list of data. I am logging the list in the Console. The console log doesn't have any data. What could be the issue? I am injecting the service in the constructor of the Component and I have imported the Service from the services folder.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement