The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Loop Through Angular 2 Components with ngFor

Loop Through Angular 2 Components with ngFor

1:58
This lesson covers Angular 2’s version of looping through data in your templates: `*ngFor`. It’s conceptually the same as Angular 1’s ng-repeat, but you’ll find the syntax quite different as it aligns with #refs in Angular 2 and JavaScript “for of” loop.
Watch this lesson now
Avatar
egghead.io

This lesson covers Angular 2’s version of looping through data in your templates: ng-for. It’s conceptually the same as Angular 1’s ng-repeat, but you’ll find the syntax quite different as it aligns with #refs in Angular 2 and JavaScript “for of” loop.

Avatar
Rolando

Hi John, thanks for this series, unfortunately I haven't been able to pass through this lesson, the following error appears on my consolé.

EXCEPTION: Cannot resolve all parameters for TodoList(?). Make sure they all have valid type or annotations.

Any ideas??

In reply to egghead.io
Avatar
Nils

i dont really understand what the [TodoService] in main.ts gives us ?. We still need to import it in every "module"? that wants to use it. tnx

Avatar
kevin

perhaps you are running into some syntax changes that have occurred in angular2. You may need to import NgFor like this

import {NgFor} from "angular2/common";

The usage has also changed it seems from ng-for to ngFor?

In reply to Rolando
Avatar
Leon

The TodoService just contains the todo array. So 1 module pushes todo's into that Array, and the other module just displays the todos in the array on the page. Yeah it seems to be exactly like Angular 1, where you have to import a service into every Controller where you want to use it.

In reply to Nils
Avatar
Goma Games

in the latest version of angular2, instead of using

<li *ngFor="#todo of todoService.todos">

the new syntax should be

<li *ngFor="let todo of todoService.todos">
Avatar
Bill

I believe this video was changed in the course, because there is no ToDo service currently being worked on. Please remove the non-related discuss posts to this new current video.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?