Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

266
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda