Skip to content

Commit 1d99d40

Browse files
committed
docs: Add Stackblitz examples for component communication
1 parent a3e123a commit 1d99d40

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,8 @@ export class AppComponent {
826826
}
827827
```
828828

829+
[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-cc1rfn?file=src%2Fmain.ts)
830+
829831
### None View Encapsulation
830832

831833
Disables encapsulation; styles can affect other components.
@@ -844,6 +846,8 @@ export class AppComponent {
844846
}
845847
```
846848

849+
[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-gzsxag?file=src%2Fmain.ts)
850+
847851
[Back to top⤴️](#table-of-contents)
848852

849853
## Component Communication
@@ -894,6 +898,8 @@ export class ParentComponent {
894898
<app-child [message]="message"></app-child>
895899
```
896900

901+
[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-qqjcgn?file=src%2Fmain.ts)
902+
897903
### Child to Parent
898904

899905
**Output Decorator** - The `@Output` decorator is used to pass data from a child component to a parent component. It allows the child component to emit events that the parent component can listen to.
@@ -947,6 +953,8 @@ export class ParentComponent {
947953
<p>{{ message }}</p>
948954
```
949955

956+
[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-4qgrhm?file=src%2Fmain.ts)
957+
950958
[Back to top⤴️](#table-of-contents)
951959

952960
## Siblings to Siblings Communication
@@ -1025,8 +1033,11 @@ export class Sibling2Component {
10251033
```html
10261034
<!--sibling2.component.html-->
10271035
<p>{{ message }}</p>
1036+
<button (click)="receiveMessage()">Receive Message</button>
10281037
```
10291038

1039+
[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-uvqypy?file=src%2Fmain.ts)
1040+
10301041
Example 2 :
10311042

10321043
**Using RxJS Subjects** - RxJS Subjects are a way to share data and events between components in Angular. You can create a Subject that emits events and subscribe to those events in the components.
@@ -1128,6 +1139,7 @@ export class Sibling1Component {
11281139
```html
11291140
<!--sibling1.component.html-->
11301141
<button (click)="sendMessage()">Send Message</button>
1142+
<app-sibling2></app-sibling2>
11311143
```
11321144

11331145
```typescript
@@ -1149,6 +1161,8 @@ export class Sibling2Component {
11491161
<p>{{ message }}</p>
11501162
```
11511163

1164+
[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-nezkvf?file=src%2Fmain.ts)
1165+
11521166
[Back to top⤴️](#table-of-contents)
11531167

11541168
## Data binding

0 commit comments

Comments
 (0)