deviceorientation not working as expected

Viewed 325

I'm trying some code with the deviceorientation listener and it's not working as I would expect. I've tried a couple different methods (shown below) and both work fine when manually changing Chrome's Debugger Sensors, however, I can't get it to work on any mobile device automatically.

I'm using this site as a reference and demo:

-https://www.audero.it/demo/device-orientation-api-demo.html

-https://code.tutsplus.com/tutorials/an-introduction-to-the-device-orientation-api--cms-21067

The demo above is working great on my phone, but when I try to implement the same code into what I'm working on, nothing happens.

export class AppComponent {
    absolute: boolean = false;
    alpha: number = 0;
    beta: number = 0;
    gamma: number = 0;
    private orientation$ = fromEvent(window, 'deviceorientation');

    constructor() { }

    ngAfterViewInit() {
    // Method 1
        window.addEventListener('deviceorientation', (e) => console.log(e));

    // Method 2
        this.orientation$.subscribe((res: any) => console.log(res));
    }
}

Any ideas what I'm missing?

0 Answers
Related