Reputation: 5644
I have the following Angular 2 service that is fetching data every 5 seconds:
import { Observable } from "rxjs/Rx";
import { Http, Response } from '@angular/http';
@Injectable()
export class DataService{
getData():{
return Observable
.interval(5000)
.flatMap(() => this.http.get('http://some_url'))
.map((res: Response) => res.json())
}
Is there a way to have this service executing the request at the start? Otherwise it will wait for 5 seconds before the first execution.
Upvotes: 3
Views: 1718