我得到了这个错误
类型'number,number,number‘上不存在
属性'foo’
我不明白为什么或者怎么解决这个问题。这是一个,如果你能帮忙的话
ngOnInit(): void {
new Observable();
const foo = of(45);
const bar = interval(2000);
const baz = timer(1000);
// const faz = from(1, 2, 3, 4);
this.newCombineLatest = combineLatest(foo, bar, baz)
.pipe(
tap(res => {
console.log(this.index++, "foo", res.foo, ", bar: ", res.bar);
}),
take(10)
)
.subscribe(() => {
value => console.log(value);
});
}发布于 2021-03-24 19:26:15
参见combineLatest的文档--可观测输出是一个数组,其值对应于顺序可观测输入的最新发射量。
数组是数字索引的,因此res是由三个数字组成的数组。它没有对象键(除了length属性和数组方法等)。更重要的是,JavaScript无法知道您的变量名是foo,并且它应该将属性foo分配给数组。
相反,使用与可观察的参数顺序相对应的数字索引:
console.log(this.index++, "foo", res[0], ", bar: ", res[1]);https://stackoverflow.com/questions/66787923
复制相似问题