0
0
Angularframework~10 mins

BehaviorSubject as simple store in Angular - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a BehaviorSubject with initial value 0.

Angular
import { BehaviorSubject } from 'rxjs';

const count$ = new BehaviorSubject([1]);
Drag options to blanks, or click blank then click option'
A0
Bnull
Cundefined
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using null or undefined as initial value causes errors.
Leaving the initial value empty.
2fill in blank
medium

Complete the code to subscribe and log the current value from the BehaviorSubject.

Angular
count$.[1](value => console.log(value));
Drag options to blanks, or click blank then click option'
Aemit
Bsubscribe
Clisten
Dobserve
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like emit or listen.
Trying to access value directly without subscribing.
3fill in blank
hard

Fix the error in updating the BehaviorSubject's value.

Angular
count$.[1](count$.value + 1);
Drag options to blanks, or click blank then click option'
Aset
Bchange
Cupdate
Dnext
Attempts:
3 left
💡 Hint
Common Mistakes
Using set or update which do not exist on BehaviorSubject.
Trying to assign value directly.
4fill in blank
hard

Fill both blanks to create a simple store with BehaviorSubject and expose it as an observable.

Angular
private countSubject = new BehaviorSubject([1]);

public count$ = this.countSubject.[2]();
Drag options to blanks, or click blank then click option'
A0
BasObservable
Csubscribe
Dnext
Attempts:
3 left
💡 Hint
Common Mistakes
Exposing the BehaviorSubject directly instead of asObservable.
Using subscribe instead of asObservable.
5fill in blank
hard

Fill all three blanks to implement an increment method that updates the BehaviorSubject's value.

Angular
increment() {
  const current = this.countSubject.[1];
  this.countSubject.[2](current [3] 1);
}
Drag options to blanks, or click blank then click option'
Avalue
Bnext
C+
Dsubscribe
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to subscribe inside increment method.
Using wrong operators or methods to update value.