Angular4 async pipe will lose observer reference with mdDialog

Let's say I have a component named FooComponent

and in my html template there is an element using an async pipe [data]="messageService.messages | async"

.

The MessageService

property messages

is a Behavior object:

private _messages = new BehaviorSubject(this._loadedMessages[this.environmentId]);
get messages(): BehaviorSubject<Message[]> { return this._messages; }

      

In FooComponent

I can open mdDialog

, and in this dialog a function is called MessageService

that changes the value of the object's behavior:

this._messages.next(this._loadedMessages[this.environmentId]);

      

The problem is that after closing the dialog in the function Subject.prototype.next(value)

SubjectBehavior

, it is FooComponent

no longer an observer.

I know the aync pipe prevents the memory leak by unsubscribing the destruction of components, but opening the dialog does not destroy FooComponent

...

Why am I losing my observer link?

+3


source to share





All Articles