如何在 Angular 中使用 subscribe-next RxJS?
How to use subscribe-next RxJS in Angular?
我正在学习 rxjs。我有一个数组的可观察对象。我想使用 subscribe 和 next 在函数中添加一些水果。我写了但不对,我可以帮助你吗?非常感谢!
const fruits = from([
"apple",
"banana",
"cherry"]);
fruits.subscribe(fruit => this.next(fruit));
const myObserver = {
next: (item) => console.log('next: ', item),
error: (err) => console.log('err: ', err),
complete: () => console.log("Observable completed")
};
of([
"apple",
"banana",
"cherry"
]).subscribe(myObserver);
setTimeout(() => myObserver.next(["Apple"]) ,2000);
你的练习答案:D
fruits.subscribe(fruit => toConveyorBelt(fruit));
我正在学习 rxjs。我有一个数组的可观察对象。我想使用 subscribe 和 next 在函数中添加一些水果。我写了但不对,我可以帮助你吗?非常感谢!
const fruits = from([
"apple",
"banana",
"cherry"]);
fruits.subscribe(fruit => this.next(fruit));
const myObserver = {
next: (item) => console.log('next: ', item),
error: (err) => console.log('err: ', err),
complete: () => console.log("Observable completed")
};
of([
"apple",
"banana",
"cherry"
]).subscribe(myObserver);
setTimeout(() => myObserver.next(["Apple"]) ,2000);
你的练习答案:D
fruits.subscribe(fruit => toConveyorBelt(fruit));