Angular 4: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'

前端 未结 5 1571
北恋
北恋 2020-12-08 13:47

i need your help, i\'m trying to display some datas from my firebase but it trhows me an error like InvalidPipeArgument: \'[object Object]\' for pipe \'AsyncPipe\'

5条回答
  •  生来不讨喜
    2020-12-08 13:58

    I found another solution to get the data. according to the documentation Please check documentation link

    In service file add following.

    import { Injectable } from '@angular/core';
    import { AngularFireDatabase } from 'angularfire2/database';
    
    @Injectable()
    export class MoviesService {
    
      constructor(private db: AngularFireDatabase) {}
      getMovies() {
        this.db.list('/movies').valueChanges();
      }
    }
    

    In Component add following.

    import { Component, OnInit } from '@angular/core';
    import { MoviesService } from './movies.service';
    
    @Component({
      selector: 'app-movies',
      templateUrl: './movies.component.html',
      styleUrls: ['./movies.component.css']
    })
    export class MoviesComponent implements OnInit {
      movies$;
    
      constructor(private moviesDb: MoviesService) { 
       this.movies$ = moviesDb.getMovies();
     }
    

    In your html file add following.

  • {{ m.name }}
提交回复
热议问题