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

122
Visualizações
How to create Undo and Redo value functionality from input tag in Angular?

I want to create a functionality which undo and redo value from input tag in angular. What I supposed to do is as follows if I enter Hello in input:

  1. click undo button: show hell
  2. click undo button: show hel
  3. click redo button: show hell
  4. click redo button: show hello

Please help. Thanks

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

0

You can do in your .ts:

  inputValue: string = '';
  inputStates: string[] = [];
  undoStats: number = 0;

  onChanges(change) {
    this.inputStates.push(change);
    this.undoStats = 0;
  }

  undo() {
    this.undoStats++;
    this.inputValue = this.inputStates[this.inputStates.length - (this.undoStats + 1)];
  }

  redo() {
    if (this.undoStats > 0) this.undoStats--;
    if (this.undoStats >= 0)
      this.inputValue = this.inputStates[this.inputStates.length - (this.undoStats + 1)];
  }

and in html:

<div>
  <input
    type="text"
    [(ngModel)]="inputValue"
    (ngModelChange)="onChanges($event)"
  />
  <br />
  <button (click)="undo()">Undo</button><button (click)="redo()">Redo</button>
</div>

You'll only need to find a point at which you'll clear this.inputStates (like onSubmit or something like that).

about 4 years ago · Juan Pablo Isaza Relatório

0

There is the functionality already present by the system in input. You can try out the control z button and control y button.

If you want to create your own by then you have to add the mapping of user input fields and values and listen to the undo and redo events and based on that do the undo and redo by going up and down the array

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