MdDialog Component throwing ObjectUnsubscribedError
Bug
Expected Behavior: When exiting a dialog, no error should be thrown.
Current Behavior: The dialog throws an ObjectUnsubscribedError which comes from this chunk of code.
/**
* Callback, invoked whenever an animation on the host completes.
* \@docs-private
* @param {?} event
* @return {?}
*/
MdDialogContainer.prototype._onAnimationDone = function (event) {
this._onAnimationStateChange.emit(event);
if (event.toState === 'enter') {
this._trapFocus();
}
else if (event.toState === 'exit') {
this._onAnimationStateChange.complete();
}
};
When I change the code to this, the error is no longer thrown.
MdDialogContainer.prototype._onAnimationDone = function (event) {
if (event.toState === 'exit') {
this._onAnimationStateChange.complete();
return;
}
if (event.toState === 'enter') {
this._trapFocus();
}
this._onAnimationStateChange.emit(event);
};
What are the steps to reproduce?
I'm unable to reproduce this in a plunker but thought if I posted the changes I made to fix it that someone could possibly shed some light on this.
Which versions of Angular, Material, OS, browsers are affected?
Angular 4.0.1, Material - pulled from Master
Yes, happens to me as well from time to time.
@fxck should I just ignore it? It happens every time for me.
@jelbourn seems like this is difficult to reproduce, but maybe we can inspect the logic or add a check to not emit if the stream is complete for safety?
I'm also getting this error from snackbar
Any update on this? Still experiencing unsubscribed errors when dialog is closed
I don't see a reason why _onAnimationStateChange should need to complete anyway. The only use of its completion event is here, but the event is already filtered to 'exit' events anyway, so it looks like you wouldn't need the onCompletion callback and could put everything in the onNext callback.
Maybe @crisbeto could comment since he initially made the change.
@saylorRevIQ, can you post the code that's causing the error for you? It's hard to know what is going on without an example. While we can always add a check that prevents the _onAnimationStateChange from emitting after it was completed, I'm not sure that is the issue. I've tried downgrading Angular to 4.0.3 and adding a subscribe and an emit right after the complete call and still couldn't manage to get the error.
@willshowell, the _onAnimationStateChange is completed, because it spares us the trouble having to save the subscription and to unsubscribe manually.
@crisbeto The implementation is pretty straightforward. Let me know if you need to see something else.
openGroupSelect() {
let dialogRef = this.dialog.open(GroupSelectDialogComponent, {
data: this.filter.groups,
});
dialogRef.afterClosed().subscribe(group => {
if (group) {
this.updatePayers(group);
}
})
}
That's the method to open the dialog and below is the code for the dialog component. `import { Component, Input, OnInit, OnDestroy } from '@angular/core'; import { MdDialog, MdDialogRef } from '@angular/material'; import { Payer, PayerGroup, PayerConfig } from '../../../server/payer' import { Inject } from '@angular/core'; import { MD_DIALOG_DATA } from '@angular/material';
@Component({ //moduleId: module.id, selector: 'group-select-dialog', templateUrl: './group-select-dialog.component.html' }) export class GroupSelectDialogComponent {
public groups: any;
public selectedGroup: PayerGroup;
public alive: boolean = true;
constructor(@Inject(MD_DIALOG_DATA) groups: any, public dialogRef: MdDialogRef<GroupSelectDialogComponent>) {
this.groups = groups;
}
selectGroup(group: PayerGroup) {
this.selectedGroup = group;
}
}`
There has been some refactoring in the dialog animations. Is this still an issue?
Closing since there hasn't been any activity for a while.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.