Having trouble with using an Observable in my Angular2.rc.4 Typescript app. Check out the plunker for it here: https://embed.plnkr.co/UjcdCmN6hSkdKt27ezyI/
The issue revolves around a service that contains this code:
private messageSender : Observable<string>;
constructor() {
this.messageSender = Observable.create(observer => this.clients.push(observer));
}
public listenForMessages() : any {
console.log("Listen Requested...")
return this.messageSender;
}
I'm trying to listen to it from a component:
ngOnInit() {
this.chatter.listenForMessages().subscribe(msg => console.log(msg));
}
This leads to the error below:
EXCEPTION: Error: Unrecognized teardown 1 added to Subscription.
Error: Unrecognized teardown 1 added to Subscription.
at Subscriber.Subscription.add (Subscription.ts:151)
at Observable.subscribe (Observable.ts:93)
at LoginPage.ngOnInit (login.ts:15)
at DebugAppView._View_LoginPage_Host0.detectChangesInternal (LoginPage.template.js:29)
at DebugAppView.AppView.detectChanges (view.ts:261)
at DebugAppView.detectChanges (view.ts:377)
at DebugAppView.AppView.detectContentChildrenChanges (view.ts:280)
at DebugAppView.AppView.detectChangesInternal (view.ts:272)
at DebugAppView.AppView.detectChanges (view.ts:261)
at DebugAppView.detectChanges (view.ts:377)
BrowserDomAdapter.logError @ browser_adapter.ts:82
After many hours of investigation, I have not found solutions on other sites. The error message originates from RxJS and is triggered when the object passed into .subscribe() method isn't recognized. Even passing lambdas or pre-defined functions results in the same issue.
Any insights? Creating the Observable in the component doesn't cause issues, but subscribing in the service triggers the error... Very perplexing situation.