diff --git a/README.md b/README.md index 3642e2e..1038c25 100644 --- a/README.md +++ b/README.md @@ -86,22 +86,25 @@ export class AppModule { } @Component({ template: `

{{mesage}}

-

{{(myOtherMessage$ | async)?.payload.toString()}}

` }) -export class ExampleComponent { - public myOtherMessage$: Observable; +export class ExampleComponent implements OnDestroy { + private subscription: Subscription; + public message: string; constructor(private _mqttService: MqttService) { - this._mqttService.observe('my/topic').subscribe((message: MqttMessage) => { - this.myMessage = message.payload.toString(); + this.subscription = this._mqttService.observe('my/topic').subscribe((message: MqttMessage) => { + this.message = message.payload.toString(); }); - this.myOtherMessage$ = this._mqttService.observe('my/other/topic'); } public unsafePublish(topic: string, message: string): void { this._mqttService.unsafePublish(topic, message, {qos: 1, retain: true}); } + + public ngOnDestroy() { + this.subscription.unsubscribe(); + } } ```