简体   繁体   中英

ionic3 get all data from firebase

在此处输入图片说明

How do I get all the posts from all the users displayed in my template? I cant think of a solution,I am a new to firebase and ionic3. Could someone help me with a small snippet or code?

From your service, just return the FirebaseListObservable to your component.

@Injectable()
export class ExpenseService {

    public users: FirebaseListObservable<any[]>;

   constructor(private afDB: AngularFireDatabase){
        this.users = this.afDB.list('/users');        
   }  

   getUsers() {
    return this.users ;
  }
}

and then,

constructor(private _service: YourService) {

  _service.getUsers()
    .subscribe(users=>{
        // do something...
    })
}

and use ngFor

<li *ngFor="let user of users | async">
    {{ user.displayName}}
</li>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM