Reputation: 2536
How to pass multiple value to BehaviorSubject?
working fine with below single value
messageSource: BehaviorSubject<string> = new BehaviorSubject("");
Error with multiple values
messageSource: BehaviorSubject<[string,boolean]> = new BehaviorSubject<[string,boolean]>();
Please suggest
Upvotes: 3
Views: 2760
Reputation: 214067
BehaviorSubject
requires a default value to be passed:
messageSource: BehaviorSubject<[string,boolean]> =
new BehaviorSubject<[string,boolean]>(['', false]);
^^^^^^^^^^^
when you want to update value you should also pass array:
this.messageSource.next(['foo', true])
Also, you can use object as a value instead.
Upvotes: 4