0

Estoy intentado iterar iterar un array dentro de una template en angular pero me bota el siguiente error: core.js:4352 ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays


La condicion establecida en el *ngIf es verdadera y me muestra la template, pero no lograr iterar, la iteracion si se logra en la consola

<div *ngIf='showPresidentList; then candidatesPresidential' >
    <h3>lista de candidatos</h3>
</div>

<ng-template #candidatesPresidential>
    <ng-container *ngFor='let candidate of candidatesPresidential'>
        <div>{{candidate['Distrito Electoral']}}</div> //no se puede iterar y lanza el error
    </ng-container>  
</ng-template>

El array que quiero iterar

export class ListCandidatesComponent implements OnInit, DoCheck, OnDestroy {
    candidatesPresidential: Array<any> = [];

constructor(
    private _candidatesPresidentialService: CandidatesPresidentialService,

) {
    this.candidatesPresidential = this._candidatesPresidentialService.getCandidatesPresidential();
    
}

}


El servicio del que provienen los datos es bastante simple

@Injectable()
export class CandidatesPresidentialService {
    listCandidatePresidential: Array<any> = [];

    constructor() {
        this.listCandidatePresidential = [
            {
                'Distrito Electoral': 'NACION',
                'Organización Política': 'ACCION POPULAR',
                'Tipo Organización Política': 'PARTIDO POLÍTICO',
                Cargo: 'PRESIDENTE DE LA REPUBLICA',
                'N°': '1',
                'Primer apellido': 'BARNECHEA',
                'Segundo apellido': 'GARCIA',
                Prenombres: 'ISAAC ALFREDO',
                Sexo: 'Masculino',
            },
            {
                'Distrito Electoral': 'NACION',
                'Organización Política': 'ACCION POPULAR',
                'Tipo Organización Política': 'PARTIDO POLÍTICO',
                Cargo: 'PRIMER VICEPRESIDENTE DE LA REPUBLICA',
                'N°': '2',
                'Primer apellido': 'GARCIA',
                'Segundo apellido': 'BELAUNDE',
                Prenombres: 'VICTOR ANDRES',
                Sexo: 'Masculino',
            },
            {
                'Distrito Electoral': 'NACION',
                'Organización Política': 'ACCION POPULAR',
                'Tipo Organización Política': 'PARTIDO POLÍTICO',
                Cargo: 'SEGUNDO VICEPRESIDENTE DE LA REPUBLICA',
                'N°': '3',
                'Primer apellido': 'DEL AGUILA',
                'Segundo apellido': 'MOROTE',
                Prenombres: 'RICARDO EDMUNDO',
                Sexo: 'Masculino',
            },
    }
    getCandidatesPresidential() {
        return this.listCandidatePresidential;
    }
}
3

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.