import { Component , OnInit } from '@angular/core' ; import { CribsService } from './../services/cribs.service' ; import { UtilService } from './../services/util.service' ; import { SortByPipe } from '../pipes/sort-by.pipe' ; import { Crib } from './../crib' ; @ Component ( { selector : 'app-crib-listing' , templateUrl : './crib-listing.component.html' , styleUrls : [ './crib-listing.component.css' ] } ) export class CribListingComponent implements OnInit { cribs : Array < Crib > = [ ] ; error : string = '' ; sortField : string = 'price' ; sortDirection : string = 'asc' ; sortFields : Array < string > = [ 'address' , 'area' , 'bathrooms' , 'bedrooms' , 'price' , 'type' ] ; constructor ( private cribsService , private utilService ) { } ngOnInit ( ) { this . cribsService . getAllCribs ( ) . subscribe ( data => this . cribs = data , error => this . error = error . statusText ) ; this . cribsService . newCribSubject . subscribe ( data => this . cribs = [ data , ... this . cribs ] ) ; } }