-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Answer:1 Projection #1409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Answer:1 Projection #1409
Conversation
Gw0zdziu
commented
Dec 26, 2025
- refactor CardComponent
- refactor ListItemComponent
- declare "@for" in CardComponent
- delete conditions in CardComponent
| template: ` | ||
| <div | ||
| class="flex w-fit flex-col gap-3 rounded-md border-2 border-black p-4" | ||
| [class]="customClass()"> |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
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, | ||
| }); |
There was a problem hiding this comment.
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)"> |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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
|
Nice work and thanks for sponsoring the project |