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

174
Visualizações
The 'Object' type is assignable to very few other types

I have an angular 12 application and I have a service call which is returning an Object. I need to iterate through the object and display the values in the HTML. The problem is that I need to use strict typescript types. So "any" is not allowed. Here is my working code and this works fine if I declare files: any; But I need to use strict typescript types so "any" is not allowed.

SERVICE CALL:

public getUserUploadedFileName() {
    return this.httpClient.get(this.url);
}

TS FILE:

files: any;
this._myService
        .getUserUploadedFileName()
        .subscribe((data) => {
            this.files = data;
        }); 

HTML :

<div *ngFor="let file of files">
        {{ file }} </div>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You could get the values by:

this._myService
        .getUserUploadedFileName()
        .subscribe((data) => {
            this.files = Object.values(data);
        }); 
about 4 years ago · Juan Pablo Isaza Relatório

0

After imports section declare an interface fit your data properties:

//imports .....

export interface IResponseData {
property1:string;
property2:number;
property3:string;

}
files: Array<IResponseData>;
    this._myService
            .getUserUploadedFileName()
            .subscribe((data:Array<IResponseData>) => {
                this.files = data;
            }); 
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