Skip to content

Answer:1 [IN PROGRESS] #1312

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

allan1989
Copy link

@allan1989 allan1989 commented May 8, 2025

Answer:1

Utilisation de , input() et output().
Déplacement des styles css dans le fichier global styles.scss (est-ce bon ?)

Problème:
Comment invoquer le store de chaque card sans utiliser de conditions dans CardComponent?

@github-actions github-actions bot added 1 exercice projection answer answer sponsor sponsor the project to be reviewed PR requests a review labels May 8, 2025
customClass="bg-light-green" />
customClass="bg-light-green">
<img ngSrc="assets/img/student.webp" width="200" height="200" />
</app-card>
Copy link
Owner

Choose a reason for hiding this comment

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

the goal is to handle all the logic in the parent. You should not input the store. Very bad practise to have a service as an input.

your html structure should look like:

  <app-card // handle input and output>
      // project image
      <ng-template [cardRow]="students()" let-student>
        <app-list-item (delete)="">
         // project content
        </app-list-item>
      </ng-template>
    </app-card>
    ```

Copy link
Author

Choose a reason for hiding this comment

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

@tomalaforge Qu'est-ce que [cardRow]=students() ? Est-ce un input ? A part les variables locales, je ne vois pas d'autres attributs possibles sur un ng-template....


students = this.store.students;
cardType = CardType.STUDENT;
deleteItem = output<Event>();
Copy link
Owner

Choose a reason for hiding this comment

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

Q: why do you have an output in your parent?

<img ngSrc="assets/img/student.webp" width="200" height="200" />
}

<ng-content select="img"></ng-content>
Copy link
Owner

Choose a reason for hiding this comment

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

very good

<section>
@for (item of list(); track item) {
<app-list-item
(deleteItem)="onDeleteItem($event)"
Copy link
Owner

Choose a reason for hiding this comment

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

move this in your parent

Copy link
Owner

Choose a reason for hiding this comment

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

learn how to use a templateOutlet

private teacherStore = inject(TeacherStore);
private studentStore = inject(StudentStore);
private injector = inject(Injector);
Copy link
Owner

Choose a reason for hiding this comment

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

Q: why do you need the injector

private teacherStore = inject(TeacherStore);
private studentStore = inject(StudentStore);
private injector = inject(Injector);

readonly list = input<any[] | null>(null);
readonly type = input.required<CardType>();
readonly customClass = input('');

CardType = CardType;
Copy link
Owner

Choose a reason for hiding this comment

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

remove unused element

private teacherStore = inject(TeacherStore);
private studentStore = inject(StudentStore);
private injector = inject(Injector);

readonly list = input<any[] | null>(null);
Copy link
Owner

Choose a reason for hiding this comment

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

type your data as much as possible

onDeleteItem(id: number) {
console.log('id', id);
// Comment invoquer le store de chaque card sans faire de boucle ?
// Je passe le StudentStore en input mais n'arrive pas à l'invoquer
Copy link
Owner

Choose a reason for hiding this comment

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

you have the answer, don't pass it as an input 😉


.bg-light-green {
background-color: rgba(0, 250, 0, 0.1);
}
Copy link
Owner

Choose a reason for hiding this comment

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

you should not put anything in the global stylesheet. It will get too big.
Try to put everything at component level.

@tomalaforge
Copy link
Owner

That's a good start, and I like the fact that you are trying to find the solution without looking at the other solution. This is how you will understand what you do and you will get better.

You should look at how to use ngTemplateOutlet combine with contentChild

good luck

Looking forward your second try 💪

@tomalaforge tomalaforge removed the to be reviewed PR requests a review label May 8, 2025
@github-actions github-actions bot added the to be reviewed PR requests a review label May 12, 2025
@tomalaforge tomalaforge removed the to be reviewed PR requests a review label May 12, 2025
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