地图运算符。不同的功能类型和访问器
Map operator. Different function types and accessor
我最近在我的 Ionic 项目中更新了 Firebase 和 AngularFire2
版本:
- 火力基地:5.0.3
- AngularFire2: 5.0.0-rc.10
- rxjs 6.2.0
现在我尝试使用迁移指南将项目从常规地图升级到管道:
Migration guide AngularFire2 version5
但是如果我对以下代码块使用完全相同的示例:
///my code
let dataBaseCollection = this.store.collection('items').snapshotChanges().pipe(
map(actions =>
actions.map(a => ({ key: a.key, ...a.payload.val() }))
)
).subscribe(items => {
return items.map(item => item.key);
});
///example
afDb.list('items').snapshotChanges().pipe(
map(actions =>
actions.map(a => ({ key: a.key, ...a.payload.val() }))
)
)
我遇到以下异常:
Argument of type 'OperatorFunction' is not assignable to parameter of type 'UnaryFunction, Observable<{ const: string; return: any; }[]>>'.
Types of parameters 'source' and 'source' are incompatible.
Type 'Observable' is not assignable to type 'Observable'. Two different types with this name exist, but they are unrelated.
Property 'source' is protected in type 'Observable' but public in type 'Observable'.
我已经尝试过 rxjs 中的两个不同的运算符
从'rxjs/operators'导入{地图};
从 'rxjs/operators/map';
导入 { 地图}
感谢任何帮助。
好吧,我不知道这是否是问题所在,但有几点观察:
let dataBaseCollection
从 .subscribe
收到 Subscription
而不是物品。你不能在 subscribe
里面 return,所以你的代码应该是这样的:
let dataBaseCollection = this.store.collection('items').snapshotChanges().pipe(
map(actions => actions.map(a => ({ key: a.key, ...a.payload.val() })))
)
如果您只想映射键,则只需执行以下操作:
let dataBaseCollection = this.store.collection('items').snapshotChanges().pipe(
map(actions => actions.map(a => a.key))
)
我明白了运行。
我不知道真正的问题是什么。但是我完全删除了我的本地存储库并获取了所有新文件。
然后我重新安装了所有 NPM 文件。这方面的某个地方是我的问题。我猜想,我的任何 npm 包都是问题所在。
对不起,我不能更清楚地说明这个问题。也许以后其他人遇到同样的问题,可以在这里补充。
我最近在我的 Ionic 项目中更新了 Firebase 和 AngularFire2
版本:
- 火力基地:5.0.3
- AngularFire2: 5.0.0-rc.10
- rxjs 6.2.0
现在我尝试使用迁移指南将项目从常规地图升级到管道: Migration guide AngularFire2 version5
但是如果我对以下代码块使用完全相同的示例:
///my code
let dataBaseCollection = this.store.collection('items').snapshotChanges().pipe(
map(actions =>
actions.map(a => ({ key: a.key, ...a.payload.val() }))
)
).subscribe(items => {
return items.map(item => item.key);
});
///example
afDb.list('items').snapshotChanges().pipe(
map(actions =>
actions.map(a => ({ key: a.key, ...a.payload.val() }))
)
)
我遇到以下异常:
Argument of type 'OperatorFunction' is not assignable to parameter of type 'UnaryFunction, Observable<{ const: string; return: any; }[]>>'.
Types of parameters 'source' and 'source' are incompatible.
Type 'Observable' is not assignable to type 'Observable'. Two different types with this name exist, but they are unrelated.
Property 'source' is protected in type 'Observable' but public in type 'Observable'.
我已经尝试过 rxjs 中的两个不同的运算符
从'rxjs/operators'导入{地图}; 从 'rxjs/operators/map';
导入 { 地图}感谢任何帮助。
好吧,我不知道这是否是问题所在,但有几点观察:
let dataBaseCollection
从 .subscribe
收到 Subscription
而不是物品。你不能在 subscribe
里面 return,所以你的代码应该是这样的:
let dataBaseCollection = this.store.collection('items').snapshotChanges().pipe(
map(actions => actions.map(a => ({ key: a.key, ...a.payload.val() })))
)
如果您只想映射键,则只需执行以下操作:
let dataBaseCollection = this.store.collection('items').snapshotChanges().pipe(
map(actions => actions.map(a => a.key))
)
我明白了运行。
我不知道真正的问题是什么。但是我完全删除了我的本地存储库并获取了所有新文件。
然后我重新安装了所有 NPM 文件。这方面的某个地方是我的问题。我猜想,我的任何 npm 包都是问题所在。
对不起,我不能更清楚地说明这个问题。也许以后其他人遇到同样的问题,可以在这里补充。