问题描述
假设我要求在angularfire2中的数据是这样的: var ref = new Firebase(firebase url);
现在我可以如何将rxjs运算符(如map运算符)应用于数据
我不认为你正在看angularfire2那是v1代码...
您可以在angularfire2中使用rxjs运算符 - 数据以Observable(FirebaseListObservable或FirebaseObjectObservable)的形式返回 - 所以您可以导入并应用任何rxjs运算符到这些运算符...
$ b $一般来说,你只是把数据分配给一个变量,并使用异步管道来处理它。
@组件({
selector:'app',
templateUrl:`
< ul>
< li * ngFor =let item of async>
{{item.name}}
< / li>
< / ul>
`,
})
class AppComponent {
项目:FirebaseListObservable< any>;
构造函数(af:AngularFire){
this.items = af.database.list('/ items');
$ b 但是你可以使用rxjs运算符(一定要导入你想要的内容)
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ b $ => {
console.log(value);
返回值; //做一些值等等
})
.subscribe(data => console.log (数据));
更多信息:
Suppose I requested for data in angularfire2 like this:
var ref = new Firebase("firebase url");
Now how can I apply rxjs operator like map operator to the data coming
I don't think you are looking at angularfire2 there - that's v1 code...
You can use the rxjs operators in angularfire2 - the data is returned as an Observable (FirebaseListObservable or FirebaseObjectObservable) - so you can import and apply any of the rxjs operators to those...
In general, you just assign the data to a variable and have the template handle it with the async pipe
@Component({
selector: 'app',
templateUrl: `
<ul>
<li *ngFor="let item of items | async">
{{ item.name }}
</li>
</ul>
`,
})
class AppComponent {
items: FirebaseListObservable<any>;
constructor(af: AngularFire) {
this.items = af.database.list('/items');
}
}
But you can use the rxjs operators (be sure to import what you want)
this.af.database.list('/items')
.map(value => {
console.log(value);
return value; // do something with value etc.
})
.subscribe(data => console.log(data));
More here: AngularFire2
这篇关于如何将rxjs运算符应用于从angularfire2获得的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!