1

i want to check if the clipboard content is empty so if it is, i show an alert to the user saying the clipboard is empty else i assign the clipboard content to the variable content

this is what i have tried but it doesn't show the alert

public pastetoinput(){
    this.clipboard.paste().then(
        (resolve: string) => {
            if(resolve == "" || resolve == null){
                 alert("clipboard is empty");
            }else{
                 var content = resolve
            }
        },
        (reject: string) => {
            console.error('Error: ' + reject);
        }
    );
}
Adeojo Emmanuel IMM
  • 2,104
  • 1
  • 19
  • 28

1 Answers1

0

Have you injected the Clipboard provider in your constructor? Maybe you should also check if the resolve variable would be undefined instead of null.

Code Example:

import { Clipboard } from '@ionic-native/clipboard/ngx';

constructor(private clipboard: Clipboard) { }

public pastetoinput(){
    this.clipboard.paste().then(
        (resolve: string) => {
            if(resolve === "" || resolve === null || resolve === undefined){
                 alert("clipboard is empty");
            }else{
                 var content = resolve
            }
        },
        (reject: string) => {
            console.error('Error: ' + reject);
        }
    );
}
SparkFountain
  • 2,110
  • 15
  • 35