Reputation: 158
I'm trying to find the best way to update a value of a Behavioral Subject.
When I try to set an object's attribute value, I'm getting TypeError: Cannot add property sport, object is not extensible.
selectSport(sport: Sport){
this.match$.getValue().sport = sport;
}
What is the best way to update Subject's data ?
Upvotes: 0
Views: 109
Reputation: 6424
The following is an example how it should be implemented:
selectSport(sport: Sport) {
this.match$.next({ ...this.match$.getValue(), sport });
}
Upvotes: 2