Skip to content

Conversation

@Gw0zdziu
Copy link

  • refactor CardComponent
  • refactor ListItemComponent
  • declare "@for" in CardComponent
  • delete conditions in CardComponent

@tomalaforge tomalaforge added answer answer 1 exercice projection sponsor sponsor the project labels Dec 30, 2025
template: `
<div
class="flex w-fit flex-col gap-3 rounded-md border-2 border-black p-4"
[class]="customClass()">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of wrapping your component inside another div, you can use the host metadata property

@Component({
host: {
class: `xxx``
}
}

[name]="item.firstName"
[id]="item.id"
[type]="type()"></app-list-item>
@for (item of list(); let i = $index; track i) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if possible it's better to track on a unique property like an id,

to be sure that list has an id, you can do CardComponent<T extends {id: string}>

also, you don't have to declare i you can use $index directly inside the @for

const directive = new OptionTemplateDirective();
expect(directive).toBeTruthy();
});
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is a bit useless 😅

}
readonly optionTemplateRef = contentChild(OptionTemplateDirective, {
read: TemplateRef,
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

<ng-template appOptionTemplate let-city>
<app-list-item>
<ng-container ngProjectAs="item-name">{{ city.name }}</ng-container>
<button ngProjectAs="item-action" (click)="delete(city.id)">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ngProjectAs is not needed here, but you can use it if you prefer

private store = inject(CityStore);

cities = this.store.cities;
cardType = CardType.CITY;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed anymore

class="rounded-sm border border-blue-500 bg-blue-300 p-2"
(click)="addNewItem()">
Add
</button>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add the button to list-item, that's a common button for all cards

@tomalaforge
Copy link
Owner

Nice work and thanks for sponsoring the project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1 exercice projection answer answer sponsor sponsor the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants