import { Component , Injectable } from "@angular/core" ; import { Http } from "@angular/http" ; import 'rxjs/add/operator/map' ; import 'rxjs/add/observable/from' ; import 'rxjs/add/operator/mergeMap' ; import 'rxjs/add/operator/retry' ; import { Observable } from "rxjs/Observable" ; export interface IDigg { title : string ; subject : string ; } @ Injectable ( ) export class DiggLoader { private m_http : Http ; constructor ( private http ) { this . m_http = http ; } loadDiggs ( filter , diggs ) { filter = filter . toLowerCase ( ) ; let s = this . m_http . get ( 'https://secure.digitalsignage.com/Digg' ) . retry ( 2 ) ; s . mergeMap ( ( res ) => { let news = res . json ( ) ; return Observable . from ( news ) ; } ) . filter ( function ( data ) { if ( data . title . toLowerCase ( ) . indexOf ( filter ) > - 1 ) { return true ; } } ) . subscribe ( function ( v ) { diggs . push ( v ) ; } ) ; } }