9. Create EventListComponent
In this section we will make a EventList presentational component that will show how to use @Input() decorators and pass in data to a child component.
1. Add EventListComponent
Add a new presentational component for the event list by running the below command
ng g c event/components/event-list2. Add @Input for Attendees to the new component
Add @Input for attendees being passed in from the parent component.
import { Component, Input } from '@angular/core';
import { Attendee } from '../../../models';
@Component({
selector: 'app-event-list',
templateUrl: './event-list.component.html',
styleUrls: ['./event-list.component.scss']
})
export class EventListComponent {
@Input()
attendees: Attendee[];
}
3. Add property binding to app-event-list component selector
Add
app-event-listselector toEventComponenttemplate.Add property binding to pass into the child component the attendees.
4. ngFor the attendees on the the page
Use an Angular's
*ngForto add attendees to the component template by iterating over theattendeesarray.
Run the app and add some attendees and they should be passed down and displayed by the EventListComponent.
StackBlitz Link
Last updated