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

266
Views
How to get value from local storage for primeng dropdown

I am wondering how to get value from local storage for a dropdown and I am very stuck on it and tried some related code present in a stack overflow but no luck!

my dropdown

 <p-dropdown *ngIf="languages.length" 
[options]="languages" 
[(ngModel)]="selectedLanguage.name" optionLabel="name"
(onChange)="modo(selectedLanguage.mod)"></p-dropdown>

Saving selected language to local storage that works fine

    onChangeDropDown() {
        localStorage.setItem('selectedLanguage', this.selectedLanguage.name);
}

getting languages from a JSON file

// its not working
 this.selectedLanguage = localStorage.getItem('selectedLanguage');

//JSON data
 this.httpClient.get<any>('../assets/data/languages.json')
            .toPromise()
            .then(res => res.data as any[])
            .then(data => this.languages = data);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Isn't it because you are saving this.selectedLanguage.name and loading it as this.selectedLanguage so you have the name in this variable then?

You should search languages by name with the value from local storage.

this.selectedLanguage = languages.find((l) => l.name === localStorage.getItem('selectedLanguage'))
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!