0
Good afternoon, I’m trying to create a button to copy the text of an input, but without success, I’m trying with Clipboard and it doesn’t work, gives an error saying that 'copy()' is not a function. follows the code:
Typescript:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { FormGroup, FormBuilder, Validators, AbstractControl, FormControl} from '@angular/forms'
import { Clipboard } from '@ionic-native/clipboard/ngx';
/**
 * Generated class for the TestePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-teste',
  templateUrl: 'teste.html',
})
export class TestePage {
private orderForm: FormGroup
  constructor(public navCtrl: NavController,
     public navParams: NavParams, 
     public formBuilder: FormBuilder,
     private clipboard: Clipboard
  ) { let texto = navParams.get('texto');
  this.orderForm = this.formBuilder.group({
    resultado: texto
  })
  }
  copy(){
    // copy function
    this.clipboard.copy('Hello world').then(rs => {
     alert(rs);
   }).catch(error => {
     alert(error);
   })
  }
  ionViewDidLoad() {
    console.log('ionViewDidLoad TestePage');
  }
}
html:
<ion-header>
  <ion-navbar>
    <ion-title></ion-title>
  </ion-navbar>
</ion-header>
<ion-content padding>
  <ion-card>
    <ion-card-header>
    </ion-card-header>
    <ion-card-content>
    <form [formGroup]="orderForm" novalidate>
      <ion-item>
        <ion-label></ion-label>
        <ion-input type="text" formControlName="resultado" readonly></ion-input>
      </ion-item>
      <button ion-button (click)="copy()" >  <ion-icon ios="ios-copy" md="md-copy"></ion-icon>
      </button>
</form> 
</ion-card-content>
</ion-card>
</ion-content>
Are you testing on an emulator or right in the browser ? Because this plugin, by what I researched, has no implementation in the Browser, so calling any function of it would give error.
– Vinicius Lourenço
Really, by what I researched it would be that same, you know some other solution for desktop ?
– israel