I have created a observable
that i am subscribing
every time at button click
event .
import {Component} from '@angular/core';
import {MainService} from '..\services\main-service';
@component({
selector:'app-main',
style:'',
template:'<div> <button click="processing()">Processing</button></div>'
})
exports class AppMain{
constructor(private mainService: MainService){
}
processing(){
this.mainService.process$.subscribe((res)=>{
// doing something here ..
});
}
}
MainService
import {OnInit} from '@angular\core';
import {Observable} from 'rxjs\Observable';
export class MainService implements OnInit{
public process$;
constructor(){
this.process$ = new Observable((observer)=>{
// doing something here
observer.next();
});
}
}
Now whenever i click multiple times on this button sometimes this observable functionality run sometime not.
does i have to unsubscribe this observable after each subsciption
or have to do something else