I'm having trouble canceling a subscription for "device orientation" in Angular using (click) in HTML. I've tried multiple solutions but none seem to work. Does anyone have any ideas on how to fix this?
TS
// Watching the change in device compass heading
async watchOrientation() {
var options = {
frequency: 500,
};
this.orientation = this.deviceOrientation.watchHeading(options).subscribe(
(data: DeviceOrientationCompassHeading) => { this.orientation = data.magneticHeading.toFixed(2) },
(error: any) => console.log(error)
);
console.log('watchOrientation button clicked')
};
// Stopping watching heading change
async stopOrientation() {
this.orientation.unsubscribe()
console.log('stopOrientation button clicked');
};
HTML
<ion-item>
<ion-icon name="pin" slot="start"></ion-icon>
<ion-label>ion-item in a card, icon left, button right</ion-label>
<ion-button fill="outline" slot="end" (click)="watchOrientation()" >Start</ion-button>
</ion-item>
<ion-item>
<ion-icon name="pin" slot="start"></ion-icon>
<ion-label>ion-item in a card, icon left, button right</ion-label>
<ion-button color="danger" fill="outline" slot="end" (click)="stopOrientation()" >Stop</ion-button>
</ion-item>