foreach en angular 5
Publicado por josep (1 intervención) el 01/07/2018 21:40:09
Buenas tardes! He puesto aquí este post porque no he visto un apartado para angular, no se si va aquí.
Mi problema es que no reconoce el bucle foreach:
Pero me da este error:
Mi problema es que no reconoce el bucle foreach:
1
2
3
4
5
6
7
8
9
10
11
12
13
export class PersonalAreaAlumnComponent implements OnInit {
currentStudient: string;
studientName: string;
allStudients: StudientsInterface[];
constructor(private studientService: StudientService){
this.currentStudient = localStorage.getItem('studientEmailLS');
this.studientService.getAllStudients().subscribe(studients => this.allStudients = studients);
this.allStudients.forEach(element => {
console.log(element);
});
}
Pero me da este error:
1
RROR Error: Uncaught (in promise): TypeError: Unable to get property 'forEach' of undefined or null reference TypeError: Unable to get property 'forEach' of undefined or null reference at PersonalAreaAlumnComponent (eval code:25:9) at createClass (eval code:12697:13) at createDirectiveInstance (eval code:12542:5) at createViewNodes (eval code:14000:21) at createRootView (eval code:13889:5) at callWithDebugContext (eval code:15314:9) at debugCreateRootView (eval code:14597:5) at ComponentFactory_.prototype.create (eval code:11494:9) at ComponentFactoryBoundToModule.prototype.create (eval code:4246:9) at ViewContainerRef_.prototype.createComponent (eval code:11691:9)
Valora esta pregunta


0