import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Flashlight } from '@ionic-native/flashlight';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, public fl : Flashlight) {
}
public off(): void
{
this.fl.toggle();
setTimeout(function(){ on() }, 3000);
}
public on(): void
{this.fl.toggle();
setTimeout(function(){ off(); }, 3000);
}
}
import { Component } from '@angular/core';
import { Flashlight } from '@ionic-native/flashlight';
@Component({
selector: 'page-home',
template: `
<button ion-button (click)="on()" block outline>
Start endless intermittent
</button>
`
})
export class HomePage {
constructor(public fl: Flashlight) {}
private off(): void {
if(this.fl.isSwitchedOn()) {
this.fl.switchOff().then(() => {
setTimeout(() => {
this.on();
}, 3000);
});
}
}
public on(): void {
if(!this.fl.isSwitchedOn()) {
this.fl.switchOn().then(() => {
setTimeout(() => {
this.off();
}, 3000);
});
}
}
}
1 Like
thank you for your solution.