Issue
I want to reload my page automatically(auto postback to reload table data) if my page is open. For that I have written some code but that is not working. See my code below
import { Component, OnInit } from '@angular/core';
import { Observable,Subscription, interval } from 'rxjs';
export class ProductsComponent implements OnInit {
private updateSubscription: Subscription;
ngOnInit() {
this.updateSubscription = interval(3000).subscribe(
(val) => { this.getProducts()});
});
}
private getProducts()
{
this.employeeService.getProducts().subscribe((data:any) => {
console.log(data);
this.products=data;});
}
}
getProducts
calling rest Api. How can I got it working?
Solution
Given code in question working for me. Initially I was waiting page to reload. But when I put debug point in inspected element every interval my code was executing.
import { Observable,Subscription, interval } from 'rxjs';
export class ProductsComponent implements OnInit {
private updateSubscription: Subscription;
ngOnInit() {
this.updateSubscription = interval(3000).subscribe(
(val) => { this.getProducts()});
});
}
}
Answered By - R15
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.