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

257
Visualizações
Load elements in array dynamically in Angular

I have created a custom slider where i'm trying to load element one by one as user clicks on next and previous buttons.

Links: https://stackblitz.com/edit/angular-ivy-rwuxjd?file=src%2Fapp%2Fapp.component.ts

Initially i'm loading only first value of an array in question array

  ngOnInit(): void {
    var formData=new FormData();
    formData.append("test",'test');
    this.http.post(this.baseUrl+'api/auth/fetch', formData).subscribe(result  => {
    this.questions_lists = result;
    this.temp_questions_lists.push(this.questions_lists[0]);

questions_lists contains all the result from database but temp_questions_lists contains only first element of an array, Now on next and previous buttons i'm trying to clear array and load next value from question_lists array into temp_questions_lists array.

onNext() {
    if (this.counter != this.questions_lists.length - 1) {
      this.counter++;
      this.temp_questions_lists=[];
      this.temp_questions_lists=this.questions_lists[this.counter];
    }
  }



 onPrevious() {
    if (this.counter > 0) {
      this.counter--;
      this.temp_questions_lists=[];
      this.temp_questions_lists.push(this.questions_lists[this.counter]);
    }
  }

First time data is loaded in the slider but next time when i click on next button then i get this error :

Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed

Any solution is highly appreciated Thanks.

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

0

You need to use .push() instead of assigning.

onNext() {
  if (this.counter != this.questions_lists.length - 1) {
  this.counter++;
  this.temp_questions_lists=[];
  this.temp_questions_lists.push(this.questions_lists[this.counter]);
  }
}
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