Skip to content

Commit

Permalink
docs: Add Stackblitz examples for component communication
Browse files Browse the repository at this point in the history
  • Loading branch information
manthanank committed Oct 7, 2024
1 parent a3e123a commit 1d99d40
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,8 @@ export class AppComponent {
}
```

[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-cc1rfn?file=src%2Fmain.ts)

### None View Encapsulation

Disables encapsulation; styles can affect other components.
Expand All @@ -844,6 +846,8 @@ export class AppComponent {
}
```

[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-gzsxag?file=src%2Fmain.ts)

[Back to top⤴️](#table-of-contents)

## Component Communication
Expand Down Expand Up @@ -894,6 +898,8 @@ export class ParentComponent {
<app-child [message]="message"></app-child>
```

[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-qqjcgn?file=src%2Fmain.ts)

### Child to Parent

**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.
Expand Down Expand Up @@ -947,6 +953,8 @@ export class ParentComponent {
<p>{{ message }}</p>
```

[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-4qgrhm?file=src%2Fmain.ts)

[Back to top⤴️](#table-of-contents)

## Siblings to Siblings Communication
Expand Down Expand Up @@ -1025,8 +1033,11 @@ export class Sibling2Component {
```html
<!--sibling2.component.html-->
<p>{{ message }}</p>
<button (click)="receiveMessage()">Receive Message</button>
```

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

Example 2 :

**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.
Expand Down Expand Up @@ -1128,6 +1139,7 @@ export class Sibling1Component {
```html
<!--sibling1.component.html-->
<button (click)="sendMessage()">Send Message</button>
<app-sibling2></app-sibling2>
```

```typescript
Expand All @@ -1149,6 +1161,8 @@ export class Sibling2Component {
<p>{{ message }}</p>
```

[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-nezkvf?file=src%2Fmain.ts)

[Back to top⤴️](#table-of-contents)

## Data binding
Expand Down

0 comments on commit 1d99d40

Please sign in to comment.