Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
- @Injectable()
- export class FirebaseService {
- listings: FirebaseListObservable<any[]>;
- constructor(private af: AngularFireDatabase) {}
- getListings(){
- console.log('In getListings');
- this.listings = this.af.list('/listings') as FirebaseListObservable<Listing[]>;
- return this.listings;
- }
- }
- interface Listing{
- $key?:string;
- title?:string;
- type?:string;
- image?:string;
- city?:string;
- owner?:string;
- bedrooms?:string;
- }
- import { Component, OnInit } from '@angular/core';
- import { FirebaseService } from '../../services/firebase.service';
- @Component({
- selector: 'app-listings',
- templateUrl: './listings.component.html',
- styleUrls: ['./listings.component.css']
- })
- export class ListingsComponent implements OnInit {
- listings:any;
- constructor(private firebaseService:FirebaseService) { }
- ngOnInit() {
- this.firebaseService.getListings().subscribe(listings => {
- console.log(listings);
- this.listings = listings;
- });
- }
- }
- 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