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

269
Visualizações
How to implement changing placeholder in angular 8+?

I have an array of items. a = ['apple', 'mango', 'grape', 'papaya', 'banana', 'cucumber']. There is an input element with a placeholder as select from fruits (after fruits it should show array elements randomly or in loop infinite no of times and placeholder fruit should change every two seconds.)

eg. select from fruits apple again after 2 sec it should show select from fruits mango again after 2 sec select from fruits grape. so I want to implement a placeholder that changes every two seconds infinite no of times. This input element is in the header component of the home page. Note: This should be in angular 8+.

I tried using setInterval in ngafterviewinit I called like this

TIME_INTERVAL = 2000;

ngAFterViewInIt(){ this.timerId = window.setInterval(() => this.changePlaceholder, this.TIME_INTERVAL);}

      RANDOM_NUMBER: number = 8;
  changePlaceholder(count: number = 0) {
    let randomNumber = Math.floor(Math.random() * this.RANDOM_NUMBER);
    count = (count + randomNumber) % this.globalSearchItems.length;
    this.globalSearch.nativeElement.placeholder = this.searchType + ' ' + this.globalSearchItems[count];
  }



 ngOnDestroy(){
if(!!this.timedId){
    clearInterval(this.timerId);
    }}

searchType = 'select from fruits'

Now I want to append my item in front of fruits and change it every 2 sec randomly or in a loop doesn't matter.

html tag

 <input placeholder = {{searchType}}/>

The pb with this code is when I first login to the application the placeholder is not changing but if I click on any other component and then again come back to home component then this is working. so in short when I login first time/newly the setInterval is not calling callback function changePLaceholder

functionality should be like this https://dribbble.com/shots/9530283-Daily-UI-022-Search

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

0

You are not Binding to the placeholder of the input tag. Try doing something like this:

Example

I didn't have much time to get everything to work, this is a very basic version of what you're trying to achieve. :D

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