How do use: utils.copyToClipboard

How do use: utils.copyToClipboard

by Dorel Manolescu -
Number of replies: 1
Picture of Plugin developers

Hi Guys,

I am trying to implement the mobile view for a plugin following the documentation here:

https://docs.moodle.org/dev/Moodle_App_Plugins_Development_Guide#CoreBlockDelegate

In the template I am trying to use moodle defined copyToClipboard function:

<ion-card class="md hydrated">

    <ion-item>

        <ion-label

                class="ion-text-wrap core-course-title sc-ion-label-md-h sc-ion-label-md-s md hydrated">

                <div id="container">

                    <p>

                        <ion-button color="primary" (click)="this.utils.copyToClipboard('bobobob');">Copy</ion-button>

                    </p>

                </div>

        </ion-label>

    </ion-item>

</ion-card>

and I get the error:

index.ts:41 ERROR TypeError: Cannot read properties of undefined (reading 'copyToClipboard')


Also when trying to user the standard Ionic function:

<ion-card class="md hydrated">

    <ion-item>

        <ion-label

                class="ion-text-wrap core-course-title sc-ion-label-md-h sc-ion-label-md-s md hydrated">

                <div id="container">

                    <p>

                        <ion-button color="primary" (click)="clipboard.copy('bobobob');">Copy</ion-button>

                    </p>

                </div>

        </ion-label>

    </ion-item>

</ion-card>

I get something like

Cannot read properties of undefined (reading 'copy')

Is there something I am doing wrong here? Should I import the library or something?

Thanks!

Average of ratings: -
In reply to Dorel Manolescu

Re: How do use: utils.copyToClipboard

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Dorel,

try using the full name of the "utils" service:

(click)="CoreUtilsProvider.copyToClipboard('bobobob');"

I hope it works now!

Cheers,

Dani