1
I’m trying to display the data of some interns using a card library made by another developer. The application was all done in Angular (including lib). A few weeks ago, everything was working, but recently I went to test the application and an error appears in Typescript.
I have this function that mounts the cards on the screen:
// Monta a visualização dos cards
folhaDePagamentoEstagiariosToItemCard(folhas) {
const dados: any[] = [];
// Pipe para a formatação da moeda
const pipe = new CurrencyPipe('pt');
folhas.forEach(dado => {
const item: ItemCard = new ItemCard();
item.cabecalho = dado.Nome;
item.subtitulo = 'Lotação: ' + dado.Lotacao;
item.resumo = <string>this.sanitizer.bypassSecurityTrustHtml(
'<table>' +
'<tr><th>Estabelecimento:</th><td>' + dado.Estabelecimento + '</td></tr>' +
'<tr><th>Início do Contrato:</th><td> ' + dado.Inicio + '</td></tr>' +
'<tr><th>Término do Contrato:</th><td> ' + dado.Termino + '</td></tr>' +
'<tr><th>Bolsa Auxílio:</th><td>' + pipe.transform(dado.Proventos, 'R$') + '</td></tr>' +
'</table>');
dados.push(item);
});
return dados;
}
The card summary is where the trainees' data appears. It’s a table that uses the pattern that was set in the lib I’m using.
But I get the following error in the browser console:
core.js:14597 ERROR TypeError: folhas.forEach is not a function
at EstagiariosComponent.push../src/app/estagiarios/estagiarios.component.ts.EstagiariosComponent.folhaDePagamentoEstagiariosToItemCard (estagiarios.component.ts:62)
at SafeSubscriber._next (estagiarios.component.ts:51)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:196)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:134)
at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:77)
at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:41)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/operators/filter.js.FilterSubscriber._next (filter.js:38)
at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
Rather the function forEach
was working. Now I have this problem. I am grateful if someone can help me!
from a sheet log console, probably not an array
– Eduardo Vargas
Okay. Try changing the
forEach
forfor
, besidesArray.ForEach
be about 95% slower thanfor
. I’ll edit the answer.– Cristiano Gilberto João