Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
How to disable typing but allow copy and paste in a text box in Angular 8?

I want to restrict typing in a text box but I need to paste anything inside that textbox in Angular

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have to stop the event propagation if the combination pressed is different than the one you choose.

You can do it like this:

public onInput(event: KeyboardEvent) {
  //if is pressed a different key than c or v, or the ctrl key isn't pressed stop event
  if (!event.ctrlKey || (event.key.toLowerCase() !== 'c' && event.key.toLowerCase() !== 'v')) {
    event.stopImmediatePropagation();
    event.stopPropagation();
    event.preventDefault();
  } 

  // else execute the default event behaviour
}
<input type="text" (keydown)="onInput($event)">

Hope it helps. ^^

P.S.: You have to use the event keydown for this to work.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda