rxjs并订阅集合中的新值

时间:2018-11-19 13:09:15

标签: rxjs

我如何从不断变化的来源进行订阅?

$1,i

1 个答案:

答案 0 :(得分:1)

您应该封装数组,使其与可以观察到的主题紧密结合:

myArray = [1,2,3,4,5];
const observable = new Rx.Subject();
observable.next(myArray);

const subscribe = observable.subscribe(val => console.log(val));

myArray.push(10);
observable.next(myArray);  // after each push reemit the array

myArray.push(11);
observable.next(myArray);