How to get device orientation correctly after main plugin deprecation

I need to get the device orientation to make some kind of compass. I saw that the old plugin | [2] used for this is now deprecated and that is suggested to use the W3C Device Orientation API now.

I tried to use it this way:

this.window.addEventListener("deviceorientation", function(event) {
    console.log(event);
}, true);

but the main orientation values (alpha, beta and gamma) are always null. I tried to turn on the GPS too see if anything changes, but does not.

I tried other events related to changes of orientation, but these don’t even fire, I belive this is because the orientation values are always null.

this.window.addEventListener("orientationchange", (event) => {
    console.log(event, screen.orientation.angle);      				    
}, true);

this.window.onorientationchange = (event) => { 
    console.log(event, screen.orientation.angle);
};

Am I doing something wrong? Is there other easier or correct way to get these informations?

Well, I tried to use the deprecated plugin anyway and it gives me error code 3 when I try to use. Checking the docs I can see that it’s because the plugin can’t find the magnetic sensor of my device.

So, as stated here, either my device does not have a magnetic sensor, or the vendor has not implemented support for it in the OS.