import { Injectable } from '@angular/core' ; import { Resolve , ActivatedRouteSnapshot , RouterStateSnapshot } from '@angular/router' ; import { AngularFire , FirebaseListObservable } from 'angularfire2' ; import { ChatItem } from '../interfaces/chat-item.interface' ; @ Injectable ( ) export class MessagesResolver implements Resolve < any > { param { AngularFire } angularFire constructor ( private angularFire ) { } param { ActivatedRouteSnapshot } route param { RouterStateSnapshot } state returns { Promise < FirebaseListObservable < ChatItem [ ] > > } resolve ( route , state ) { const list = this . angularFire . database . list ( '/messages/' , { query : { limitToLast : 100 } } ) ; return new Promise ( ( resolve , reject ) => { list . first ( ) . subscribe ( ( ) => resolve ( list ) , reject ) ; } ) ; } }