首页 > 解决方案 > 带有构造函数的陀螺仪离子角度误差

问题描述

我从https://github.com/NeoLSN/cordova-plugin-gyroscope实现了陀螺仪,然后,当我将它作为 Angular 导入时,我得到了

找不到名称“构造函数”。以及有关以下从https://ionicframework.com/docs/native/gyroscope导入的其他错误。

有人有完整版吗?

    import { Gyroscope, GyroscopeOrientation, GyroscopeOptions } from '@ionic-native/gyroscope/ngx';

    constructor(private gyroscope: Gyroscope) { }

    ...

    let options: GyroscopeOptions = {
    frequency: 1000
    }

     this.gyroscope.getCurrent(options)
    .then((orientation: GyroscopeOrientation) => {
    console.log(orientation.x, orientation.y, orientation.z, orientation.timestamp);
    })
    .catch()


    this.gyroscope.watch()
    .subscribe((orientation: GyroscopeOrientation) => {
    console.log(orientation.x, orientation.y, orientation.z, orientation.timestamp);
    });

标签: angularionic-frameworkgyroscopedevicemotion

解决方案


  1. 您需要导入app.module.ts
import { Gyroscope, GyroscopeOrientation, GyroscopeOptions } from '@ionic-native/gyroscope/ngx';
  1. 添加到ngmodule
@NgModule({
   ...
   ...
   ...
  providers: [....,Gyroscope],
})

在此步骤之后,您应该完成。


推荐阅读