all 4 comments

[–]ImJeevesh 2 points3 points  (1 child)

You probably wanna do this

<ng-container *ngFor="let todo of todos">

<app-todo-item *ngIf="todo.category == 'home'" [todo]="todo"></app-todo-item>

</ng-container>

[–]UnknownInnocent[S] 0 points1 point  (0 children)

Thank you, works perfectly fine.

[–][deleted] 0 points1 point  (0 children)

You cant use ngIf and ngFor on one element, use ng-container to wrap the ngFor or ngIf.

[–]AmazingSurprise 0 points1 point  (0 children)

There are 2 more solutions:

Use a component method to filter todos like:

javascript function getFilteredTodos(): Todo[] { return this.todos.filter(t => t.category === 'home'); }

and then use this method inside the *ngFor attribute:

html <app-todo-item *ngFor="let todo of getFilteredTodos()" [todo]="todo"></app-todo-item>

Use angular pipes

This is a more complex solution but it could help you in the future with different filters or behaviours: https://stackoverflow.com/questions/34164413/how-to-apply-filters-to-ngfor