Component Inputs
Part of the Fundamentals section of Coddy's Angular journey. Lesson 27 of 55.
An input lets a parent configure a child. The decorator marks the field as data that the child accepts. Here the parent supplies a value using a property binding on the child selector.
// Child class field: @Input() label="Default";
// Child template: <p>{{label}}</p>
// Parent template: <name-card [label]="'Fern'"></name-card>Use the Input decorator to declare an incoming field. Bind expressions for values that come from parent data; a plain text attribute supplies literal text. The child renders its input but does not own the parent state.
Challenge
MediumPass the parent name signal into ProductCard and render it inside a. Renaming changes Pears to Plums in the child.
Edit the supplied files. Press Run preview to refresh the preview after edits, then use Check or Run code to grade your work. Keep the requested element IDs.
Try it yourself
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="styles.css"></head><body><app-root></app-root><script type="module" src="main.ts"></script></body></html>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
1Meet Angular
Angular in ActionA Standalone ComponentComponent FieldsTypeScript in ComponentsRecap: Meet Angular7Forms and Validation
Two-Way BindingNormalizing Form TextSubmitting a FormValidation GuardsRecap: Forms2Template Bindings
Text InterpolationProperty BindingClass BindingStyle BindingRecap: Template Bindings5Conditions and Lists
Conditional ViewsRendering ListsEmpty List ViewsFiltering ViewsRecap: Control Flow6Reusable Components
Child ComponentsComponent InputsComponent OutputsContent ProjectionRecap: Components9Services and Shared State
Injecting a ServiceSharing Service StateService CommandsDerived Service StateRecap: Shared State