Use the plugin Clipboard
, see below:
Installation
ionic cordova plugin add cordova-clipboard
npm install @ionic-native/clipboard
Insert into modules
Add the Clipboard
in the modules of AppModule
, see below:
import { Clipboard } from '@ionic-native/clipboard';
....
@NgModule({
imports: [
...
providers: [Clipboard]
...
})
export class AppModule {}
Insert on page
Finally insert on the page, below the function onCopy
will put the text passed on it to clipboard:
import { Clipboard } from '@ionic-native/clipboard';
export class Page {
constructor(private clipboard: Clipboard) { }
onCopy(text) {
this.clipboard.copy(text);
}
}
Works on Ionic 3.9.2?
– israel
When I used it was still in version 3, it should probably work.
– André Lins
Ionic 4 says copy is not part of the element
– israel
The library has changed, now it has a /ngx at the end. but now for this error: Typeerror: Object(...) is not a Function at Clipboard.copy (http://localhost:8100/build/vendor.js:79857:124)
– israel