emihud
emihud

Reputation: 158

Angular: Behavioral Subject's value object is not extensible

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

Answers (1)

Rafi Henig
Rafi Henig

Reputation: 6424

The following is an example how it should be implemented:

selectSport(sport: Sport) {
  this.match$.next({ ...this.match$.getValue(), sport });
}

Upvotes: 2

Related Questions