简体   繁体   中英

Convert Angular to plain JavaScript

This is example code for a plugin to an Ionic/Capacitor/Angular project:

import { ForegroundService } from '@awesome-cordova-plugins/foreground-service/ngx';


constructor(public foregroundService: ForegroundService) { }

...

startService() {
// Notification importance is optional, the default is 1 - Low (no sound or vibration)
  this.foregroundService.start ('GPS Running', 'Background Service', 'drawable/fsicon');
}

stopService() {
// Disable the foreground service
  this.foregroundService.stop();
}

I'm not familiar with Angular, and there's no plain JavaScript (not Typescript) example. How would this code look in plain JavaScript?

I'm not an Ionic expert, but after reading the docs I bet that it should be used like this:

// import without `ngx`
import { ForegroundService } from '@awesome-cordova-plugins/foreground-service';

// create the object from class
const foregroundService = new ForegroundService();

// start the service
foregroundService.start('GPS Running', 'Background Service', 'drawable/fsicon');

// stop the service
foregroundService.stop()

Learn more about using Ionic Native components in React section was particularly useful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM