Answer the question
In order to leave comments, you need to log in
How to track changes to a variable inside a component?
1. There is an array inside the component;
2. A new element is added to this array in several different places inside the component (in the createMessage() method and inside the getIncomingMessagesStream() subscriber);
3. Every time a new element is added to the array, you need to perform several actions at once (scroll down the page and some more);
4. Instead of writing additional actions in several places, I want to do it at one point inside the component when a new value is added to my array.
How to do it?
Answer the question
In order to leave comments, you need to log in
It is possible to throw out data in general in service which to zaprovaydit in the general module for these components.
Well, in the service itself, if on the example of user_id:
@Injectable()
export class DataService {
private userIdSubject = new Subject<number>();
$userId = this.userIdSubject.asObservable();
setUserId(id: number) {
this.userIdSubject.next(id);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question