• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

161
Views
La propiedad 'copia' no existe en el tipo 'Portapapeles'

Estoy tratando de copiar un texto cuando se hace clic en un botón. Intenté seguir la documentación de Angular ( https://material.angular.io/cdk/clipboard/overview#programmatically-copy-a-string ) pero mi terminal me da el siguiente error al compilar:

La propiedad 'copia' no existe en el tipo 'Portapapeles'

Aquí está mi archivo .ts:

 export class myComponent implements OnInit { constructor(private clipboard: Clipboard) {} ngOnInit(): void {} copyTest() { this.clipboard.copy("test"); // Property 'copy' does not exist on type 'Clipboard'. } }

Aquí está mi archivo .html:

 <button [cdkCopyToClipboard]="copyTest()">Click to copy</button>

Y aquí está mi archivo app.module.ts:

 import { ClipboardModule } from "@angular/cdk/clipboard"; @NgModule({ declarations: [ AppComponent, myComponent, ], imports: [ ClipboardModule, ] })

¿Alguna idea de por qué se produce este error?

about 3 years ago · Santiago Trujillo
2 answers
Answer question

0

Debe faltar la importación correcta para el Portapapeles.

Intente agregar: import { Clipboard } from '@angular/cdk/clipboard'; a su archivo .ts, así como a su app.module.ts.

También hay un Portapapeles de interfaz que su IDE probablemente acepte como TS válido.

about 3 years ago · Santiago Trujillo Report

0

Prueba esto en su lugar:

 <button [cdkCopyToClipboard]="copyTest('Test!')">Click to copy</button> copyTest(test: string) { this.clipboard.copy(test); }
about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error