[英]Angularfire2 query using navParams not working
I want to get some data using navParams
but it is not working but if I provide static value then it's work. 我想使用navParams
获取一些数据,但是它不起作用,但是如果我提供静态值,那就可以了。 I don't know what is wrong. 我不知道怎么了 Here is my code that does not work and return empty 这是我的代码不起作用,返回空
console.log(this.navParams.get('id')) // prints 10
const id = this.navParams.get('id');
this.categoryRef = this.db.list('/category', ref => ref.orderByChild('id').equalTo(id));
this.category = this.categoryRef.snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
if I give static value then it works like 如果我给静态值,那么它就像
const id = 10;
this.categoryRef = this.db.list('/category', ref => ref.orderByChild('id').equalTo(id));
this.category = this.categoryRef.snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
Can you try like below? 你可以像下面这样尝试吗?
myId:number;//declare a global variable
constructor(){
this.myId=this.navParams.get('id');
this.categoryRef = this.db.list('/category', ref =>
ref.orderByChild('id').equalTo(this.myId));
this.category = this.categoryRef.snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.