You can create an Observable of the service and subscribe in home.ts
Your service
//create a Subject
private percentSource:Subject<any>=new Subject<any>();
//create a Observable
percentEvent:Observable<any>=this.percentSource.asObservable();
...
calculateProgress() {
if (this.showProgressbar = true) {
...
//send a change of observable with next
this.percentSource.next(percentage); //return as result the percent
...
} else {
...
}
}
then, in your home you can subscribe to the observable in the function tiggerEven or in progressBar.component in the ngOnInit function
triggerEvent(){
this.service.showProgressbar = true;
//takeWhile make you unsubscribe if condition is not successfully
//NOT put if you subscribe in your progressBar.component
this.service.percentEvent
.takeWhile(() =>this.progress!=100)
.subscribe(result=>
{
this.progress=result;
}
}