Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: how to refresh data every 5 second using observable


I am quite new to angular2 and rxjs. I am trying to create an angular2 app that gets some data from jsonAPI,

i want to get data every 5 second, i found a solution with Observable.interval(5000) but i have some Error while compiling,

how to insert Observable.interval(500) in ngOnInit() code


import { Component, OnInit } from '@angular/core';

import { IProduct } from './product';
import { ProductService } from './product.service';

templateUrl: 'app/products/product-list.component.html',
styleUrls: ['app/products/product-list.component.css']
export class ProductListComponent implements OnInit {
pageTitle: string = 'Product List';
imageWidth: number = 50;
imageMargin: number = 2;
showImage: boolean = false;
listFilter: string;
errorMessage: string;

products: IProduct[];

constructor(private _productService: ProductService) {


toggleImage(): void {
this.showImage = !this.showImage;

ngOnInit(): void {
.subscribe(products => this.products = products,
error => this.errorMessage = error);

onRatingClicked(message: string): void {
this.pageTitle = 'Product List: ' + message;

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: how to refresh data every 5 second using observable


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription