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

296
Views
Multiselect not working when array is initialized

I am using primeng Multiselect, I have written some logic to push data based on search value from backend, for pushing element we have to initialize it first, other it gives me an error of push of undefined, but when I am using by initializing dropdown's array variable, it doesn't showing me the data which I got from API.

On the other hand when I am not initializing the dropdown data variable, and directly assigning data which I got from API then it is working,

I am attaching the stackblitz link where I am facing issue:

https://stackblitz.com/edit/primeng-multiselect-demo-qykbzn?file=src%2Fapp%2Fapp.component.ts

this is working code when I am not initializing it

dropdownData;

    getCountryData(countryName: string) {
        const url = 'https://restcountries.com/v3.1/name';
        this.http
            .get(`${url}/${countryName}?fullText=true`)
            .pipe(debounceTime(20000))
            .subscribe((data) => {
                this.dropdownData = data.map((item) => ({
                    ...item,
                    countryName: item.name.common,
                    code: item.fifa
                }));

                // if (localDropdownData.length) {
                //  localDropdownData.forEach((element) => {
                //      this.dropdownData.push(element);
                //  });
                // }
                console.log('data', this.dropdownData);
                this.cd.detectChanges();
            });
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try change the value assignment from

   localDropdownData.forEach((element) => {
     this.dropdownData.push(element);
   });

to

   this.dropdownData=[...localDropdownData];

array.push does not change the variable reference, hence it is not picked up by angular change detection.

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!