Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!