Using RxJS with Angular5, I have a service that contains an array. Some components will get created / destroyed / re-created, as the array is being populated.
So we have a service like so:
@Injectable
export class MyService {
public events = [];
}
then we have a component like so:
@Inject(MyService)
@Component({})
export class MyComponent {
mySub: Subscriber
constructor(private ms: MyService){}
ngOnInit(){
this.mySub = Rx.Observable.from(this.ms.events).subscribe(v => {
});
}
}
my question is - if the events array aleady has elements in it, when the component is created, it will pick up all the existing elements, but what about elements that are added to the array after the subscription is created? How can I listen for when elements are added to the array after the fact?
If I use a Subject
, the problem is I don't think it stores the historical items, just fires new ones.