Skip to content

Commit 812d7b4

Browse files
authored
Merge pull request sudheerj#8 from saiMedavarapu/master
Added RxJs question
2 parents 586b3a2 + 5b303ab commit 812d7b4

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
|128| [What are the restrictions on declarable classes?](#what-are-the-restrictions-on-declarable-classes)|
137137
|129| [What is a DI token?](#what-is-a-di-token)|
138138
|130| [What is Angular DSL?](#what-is-angular-dsl)|
139-
139+
|131| [What is an rxjs Subject?](#what-is-an-rxjs-Subject)|
140140

141141

142142

@@ -1680,6 +1680,22 @@
16801680
1. (): Used for Output and DOM events.
16811681
2. []: Used for Input and specific DOM element attributes.
16821682
3. * : Structural directives(*ngFor or *ngIf) will affect/change the DOM structure.
1683+
131. ### what is an rxjs subject in Angular
1684+
An RxJS Subject is a special type of Observable that allows values to be multicasted to many Observers. While plain Observables are unicast (each subscribed Observer owns an independent execution of the Observable), Subjects are multicast.
1685+
1686+
A Subject is like an Observable, but can multicast to many Observers. Subjects are like EventEmitters: they maintain a registry of many listeners.
1687+
``` typescript
1688+
import { Subject } from 'rxjs';
1689+
1690+
const subject = new Subject<number>();
1691+
1692+
subject.subscribe({
1693+
next: (v) => console.log(`observerA: ${v}`)
1694+
});
1695+
subject.subscribe({
1696+
next: (v) => console.log(`observerB: ${v}`)
1697+
});
16831698
1684-
1685-
1699+
subject.next(1);
1700+
subject.next(2);
1701+
```

0 commit comments

Comments
 (0)