cod_hmd_123411
cod_hmd_123411

Reputation: 1

Gyroscope Ionic Angular Error with constructor

I implemented the gyroscope from https://github.com/NeoLSN/cordova-plugin-gyroscope and then, when i imported it as an Angular i got

Cannot find name 'constructor'. And other errors concerning the import below from https://ionicframework.com/docs/native/gyroscope.

Does anyone have a complete version?

    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);
    });

Upvotes: 0

Views: 126

Answers (1)

SOHAIB BOULAICH
SOHAIB BOULAICH

Reputation: 1

  1. You need to import in app.module.ts:
import { Gyroscope, GyroscopeOrientation, GyroscopeOptions } from '@ionic-native/gyroscope/ngx';
  1. Add into ngmodule:
@NgModule({
   ...
   ...
   ...
  providers: [....,Gyroscope],
})

After this steps you should be done.

Upvotes: 0

Related Questions