on-internet
← Community

Cannot read property 'subscribe' of undefined angular

Stack Overflow ·

I have a service UserService that has a method getUsers() and this service is shared among different angular components. The method calls an API and returns the data. I want to hold the result/state of last API call so I used BehaviorSubject to hold the last state so that if different components call getUsers() there should be only one API call otherwise hold state must be returned. This is how I am implementing this private _users$: BehaviorSubject<User[]>; constructor(private http: HttpClient) { this._users$ = new BehaviorSubject([]); } getUsers(): BehaviorSubject<User[]> { if (!this._getUse

Comments

Sign in or sign up to comment and upvote.

No comments yet.