I am new to Observer in Angular4 as I have worked on Promises in AngularJs. I want to understand 2 scenarios:
Returning observable from a function so that the UI can be changed accordingly.
Returning continuous stream of data from a function which is reflected on the UI.
In a service (proc.svc.ts) file I created a function:
counter(){
public counterObserver = Observable.create(obs => {
obs.next(increment())
});
return counterObserver;
}
increment(){
setInterval(function(){
count++
},1000)
}
In the proc.component.ts file:
ngOnInit() {
this.initCounter();
}
initCounter(){
this.procSvc.counter.subscribe(count => this.count = count);
}
I am getting below error:
Property 'subscribe' does not exist on type '() => void'.
counter(), notcounter!