You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your app's `HousingLocation` template has a `HousingLocation` property to receive input.
10
9
11
10
## Conceptual preview of Inputs
12
11
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.
14
13
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.
16
15
17
16
Learn more in the [Accepting data with input properties](guide/components/inputs) and [Custom events with outputs](guide/components/outputs) guides.
18
17
19
18
<docs-workflow>
20
19
21
-
<docs-steptitle="Import the Input decorator">
22
-
This step imports the `Input` decorator into the class.
20
+
<docs-steptitle="Import the input() function">
21
+
This step imports the `input()` function into the class.
23
22
24
23
In the code editor:
25
24
26
25
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`:
28
27
29
28
<docs-codeheader="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]"/>
30
29
31
30
</docs-step>
32
31
33
32
<docs-steptitle="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><HousingLocationInfo></code> immediately after <code>.required</code>:
35
34
36
35
<docs-codeheader="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]"/>
37
36
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.
39
38
40
39
1. Save your changes and confirm the app does not have any errors.
41
40
@@ -44,7 +43,7 @@ In the code editor:
44
43
45
44
</docs-workflow>
46
45
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.
48
47
49
48
<docs-pill-row>
50
49
<docs-pillhref="guide/components/inputs"title="Accepting data with input properties"/>
0 commit comments