1
1
---
2
- title : Component output
3
- description : Component output
2
+ title : Component outputs
3
+ description : Component outputs
4
4
course : angular-20
5
- slug : " reusable-components-component-output "
5
+ slug : " reusable-components-component-outputs "
6
6
---
7
7
8
- import { Steps } from ' @astrojs/starlight/components' ;
8
+ import { Steps } from " @astrojs/starlight/components" ;
9
9
import NotificationCard from " ../../../../components/ui/NotificationCard" ;
10
10
11
11
# Component output
12
12
13
- One key feature of reusable components is to notify the parent component that an action has been performed.
13
+ One key feature of reusable components is to notify the parent component that an action has been performed.
14
14
In the ` AlertBanner ` component, we want to add a button, triggering a different action based on its usage:
15
15
16
16
- in the ` TaskList ` component, we want to call a function to delete all tasks
@@ -26,49 +26,61 @@ To do so, we'll use the `output` feature of Angular.
26
26
27
27
1 . Update the ` AlertBanner ` class:
28
28
29
- ``` typescript
30
- import { output } from ' @angular/core' ;
29
+ ``` typescript
30
+ import { output } from " @angular/core" ;
31
31
32
- onSubmit = output <void >();
33
- ```
32
+ onSubmit = output <void >();
33
+ ```
34
34
35
35
2 . Update the template of ` alert-banner.html ` file:
36
36
37
- ``` html
38
- <button class =" btn"
39
- [class.btn-info] =" type() ? type() === 'info' : false"
40
- [class.btn-error] =" type() ? type() === 'error' : false"
41
- (click) =" onSubmit.emit()" >Proceed</button >
42
- ```
37
+ ``` html
38
+ <button
39
+ class =" btn"
40
+ [class.btn-info] =" type() ? type() === 'info' : false"
41
+ [class.btn-error] =" type() ? type() === 'error' : false"
42
+ (click) =" onSubmit.emit()"
43
+ >
44
+ Proceed
45
+ </button >
46
+ ```
43
47
44
48
3 . Update the ` TaskList ` class:
45
49
46
- ``` typescript
47
- deleteAllTasks () {
48
- // TODO: delete all tasks
49
- }
50
- ```
50
+ ``` typescript
51
+ deleteAllTasks () {
52
+ // TODO: delete all tasks
53
+ }
54
+ ```
51
55
52
56
4 . Update the template of ` task-list.html ` file:
53
57
54
- ``` html
55
- <app-alert-banner message =" Do you really want to delete all tasks?" type =" error" (onSubmit) =" deleteAllTasks()" />
56
- ```
58
+ ``` html
59
+ <app-alert-banner
60
+ message =" Do you really want to delete all tasks?"
61
+ type =" error"
62
+ (onSubmit) =" deleteAllTasks()"
63
+ />
64
+ ```
57
65
58
66
5 . Update the ` TaskForm ` class:
59
67
60
- ``` typescript
61
- preFillForm () {
62
- // TODO: pre fill the form with basic information
63
- }
64
- ```
68
+ ``` typescript
69
+ preFillForm () {
70
+ // TODO: pre fill the form with basic information
71
+ }
72
+ ```
65
73
66
74
6 . Update the template of ` task-form.html ` file:
67
75
68
- ``` html
69
- <app-alert-banner message =" Do you want to prefill Form?" type =" info" (onSubmit) =" preFillForm()" />
70
- ```
76
+ ``` html
77
+ <app-alert-banner
78
+ message =" Do you want to prefill Form?"
79
+ type =" info"
80
+ (onSubmit) =" preFillForm()"
81
+ />
82
+ ```
71
83
72
- 5 . Test the application.
84
+ 7 . Test the application.
73
85
74
86
</Steps >
0 commit comments