Skip to content

Commit 8ab0028

Browse files
abhideepdpkozlowski-opensource
authored andcommitted
docs: update first-app tutorial to signal inputs (angular#61876)
PR Close angular#61876
1 parent e01b4c2 commit 8ab0028

File tree

1 file changed

+9
-10
lines changed
  • adev/src/content/tutorials/first-app/steps/05-inputs

1 file changed

+9
-10
lines changed

adev/src/content/tutorials/first-app/steps/05-inputs/README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
11
# Add an input parameter to the component
22

3-
This tutorial lesson demonstrates how to create a component `@Input()` and use it to pass data to a component for customization.
3+
This tutorial lesson demonstrates how to create a component `input` and use it to pass data to a component for customization.
44

55
<docs-video src="https://www.youtube.com/embed/eM3zi_n7lNs?si=WvRGFSkW_7_zDIFD&amp;start=241"/>
66

77
## What you'll learn
8-
98
Your app's `HousingLocation` template has a `HousingLocation` property to receive input.
109

1110
## Conceptual preview of Inputs
1211

13-
[Inputs](api/core/Input) allow components to share data. The direction of the data sharing is from parent component to child component.
12+
[Inputs](api/core/input) allow components to share data. The direction of the data sharing is from parent component to child component.
1413

15-
In this lesson, you'll define `@Input()` properties in the `HousingLocation` component which will enable you to customize the data displayed in the component.
14+
In this lesson, you'll define an `input` property in the `HousingLocation` component which will enable you to customize the data displayed in the component.
1615

1716
Learn more in the [Accepting data with input properties](guide/components/inputs) and [Custom events with outputs](guide/components/outputs) guides.
1817

1918
<docs-workflow>
2019

21-
<docs-step title="Import the Input decorator">
22-
This step imports the `Input` decorator into the class.
20+
<docs-step title="Import the input() function">
21+
This step imports the `input()` function into the class.
2322

2423
In the code editor:
2524

2625
1. Navigate to `src/app/housing-location/housing-location.ts`
27-
1. Update the file imports to include `Input` and `HousingLocation`:
26+
1. Update the file imports to include `input` and `HousingLocation`:
2827

2928
<docs-code header="Import HousingLocation and Input in src/app/housing-location/housing-location.ts" path="adev/src/content/tutorials/first-app/steps/06-property-binding/src/app/housing-location/housing-location.ts" visibleLines="[1,3]"/>
3029

3130
</docs-step>
3231

3332
<docs-step title="Add the Input property">
34-
1. In the same file, add a property called `housingLocation` of type `HousingLocation` to the `HousingLocation` class. Add an `!` after the property name and prefix it with the `@Input()` decorator:
33+
1. In the same file, add a property called `housingLocation` and initialize it using `input.required()` with the type `HousingLocationInfo`. To set the type, use a generic parameter, by writing <code>&lt;HousingLocationInfo&gt;</code> immediately after <code>.required</code>:
3534

3635
<docs-code header="Import HousingLocation and Input in src/app/housing-location/housing-location.ts" path="adev/src/content/tutorials/first-app/steps/06-property-binding/src/app/housing-location/housing-location.ts" visibleLines="[13,15]"/>
3736

38-
You have to add the `!` because the input is expecting the value to be passed. In this case, there is no default value. In our example application case we know that the value will be passed in - this is by design. The exclamation point is called the non-null assertion operator and it tells the TypeScript compiler that the value of this property won't be null or undefined.
37+
You have to add `.required` after `input` to indicate that the parent component must provide a value. In our example application, we know this value will always be passed in this is by design. The `.required()` call ensures that the TypeScript compiler enforces this and treats the property as non-nullable when this component is used in a template.
3938

4039
1. Save your changes and confirm the app does not have any errors.
4140

@@ -44,7 +43,7 @@ In the code editor:
4443

4544
</docs-workflow>
4645

47-
SUMMARY: In this lesson, you created a new property decorated with the `@Input()` decorator. You also used the non-null assertion operator to notify the compiler that the value of the new property won't be `null` or `undefined`.
46+
SUMMARY: In this lesson, you created a new `input` property. You also used the `.required` method to ensure the signal value is always defined.
4847

4948
<docs-pill-row>
5049
<docs-pill href="guide/components/inputs" title="Accepting data with input properties"/>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy