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

386
Visualizações
How to get and display data from Strapi 4 using Akita Entity Service?

What I want to do: I'm trying to fetch data from my strapi api and display it.

What I'm working with: I'm working with Angular, Strapi (v4) and Akita, which I'm all completely new to and I'm using akita entity service.

Fetching the data works, but I can't display it. The collection type I'm trying to display is called question and has the the attribute name. There are 3 questions.

This is my component file:

export class HomePage {

  public questions$: Observable<Array<Question>> | undefined;

  constructor(
    protected readonly questionsService: QuestionsService,
    protected readonly questionsQuery: QuestionsQuery,
  ) {
     this.questionsService.get()
          .subscribe(console.log); 
     this.questions$ = this.questionsQuery.selectAll();
  }
}

This is my html file. Here I want to display the question by accessing the name attribute:

<ng-container *ngIf="(questions$ | async) as questions">
    <p *ngFor="let question of questions; let i = index;">
       Index: {{ i }} -
       Question: {{ question }} -
       id: {{ question.id }}
       <!--{{ question.attributes.name }} DOES NOT WORK.. Error Message: ERROR TypeError: Cannot read properties of undefined (reading 'name')-->
    </p>
</ng-container>

This is what my question model looks like (I feel like here is the problem):

export interface Question {
   id?: number;
   attributes: {
        name: string;
   };
}

This is what I see in my frontend:

Index: 0 - Question: [object Object],[object Object],[object Object] - id:
Index: 1 - Question: [object Object] - id:

It seems like all three questions are in the first index of the array. The data I get from the api looks like this: data response from api

So it seems like the data property is in the first index of the array and the meta array is in the second one. But I don't know what to do about it. Any Ideas? What I tried: change the model, but it didn't have any effect.

about 4 years ago · Juan Pablo Isaza
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