Hi i have a simple component and a service.When user clicks on submit button i am calling a service where an async subject emits a value to all its subscribers.I have done it using subject it works fine but i want to do it using Async Subject.I have made a demo here http://plnkr.co/edit/tHjPVZ5NurJRWdCM9lbt?p=preview ...This is my Service...
export class ErrorService{
latestError:AsyncSubject<>=new AsyncSubject();
error(){
this.latestError.next('form submitted');
}
}
And this is my component class where i am subscribing the asyncsubject
export class AppComponent {
result:any;
constructor(private service:ErrorService){
this.service.latestError.subscribe(err=> this.result=err);
}
onSubmit() {
this.service.error();
}
}
But this is throwing error...I dont know where i am doing wrong...Somebody please help me to rectify this error and show me how to use async subject and emit values to its subscribers