AngularJs - RXJS Observable unsubscribe
As per my comment above the new RxJs 5 Beta now changed from subscription.dispose()
to subscription.unsubscribe()
Please refer to here https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md#subscription-dispose-is-now-unsubscribe
Please see updated fiddle: here
the subscribe
function returns a Disposable
to work with and you must first return the subscription from your factory (line 60):
subscribe: function(subscription){ return msgSubject.subscribe(subscription);}
This will let you store your subscription in each controller to work with in the future. (line 21 & 42)
var boxASubscription = boxA.msgService.subscribe(function(obj) { console.log('Listerner A'); boxA.msg = obj;});
You can then call the dispose
method on the subscription when you want to unsubscribe:
boxA.unsubscribe = function(){ console.log('Unsubscribe A'); boxASubscription.dispose();};
n.b.
For some reason I couldn't get your demo to work with <md-button>
so I changed this to <button>
for the sake of the demo.