I have a component which has two buttons.when i click on the first button as per the demo in the given plunker below it emits an event and my service function emits an async subject with some values...When i click on another button i am trying to call .next event again but it is throwing some error...I have made a pluker demo here http://plnkr.co/edit/wpyV7o9JErdQMzGFZ4wp?p=preview ...If i use subject it works fine but i dont want to use subject in this case...
export class ErrorService{
latestError:AsyncSubject<string> = new AsyncSubject();
Save() {
this.latestError.next('form submitted');
this.latestError.complete();
}
Update(){
this.latestError.next('form updated');
this.latestError.complete();
}
}
This is my service class and this is how i am calling .next event for async subject.
this.service.latestError.subscribe(
err=> {
console.log('result = '+err);
this.result=err;
},
err => {
console.log('err');
},
() => {
console.log('complete');
});
And this is how i have subscribed the async subject...The click event works fine for the first time but when i click the another button it throws error.Somebody please help me to solve this error...How can i call .next() for second time using my async subject...Thanks in advance