Angularjs Ng重复Firebase snap.val
快速提问(我希望): 我正在尝试通过我的Angularjs Ng重复Firebase snap.val,angularjs,firebase,firebase-realtime-database,Angularjs,Firebase,Firebase Realtime Database,快速提问(我希望): 我正在尝试通过我的$范围中的数据ng repeat。发现我使用以下代码填充该范围: ` const businessKey='-KQ1hFH0qrvKSrymmn9d'; const rootRef=firebase.database().ref(); const discoverRef=rootRef.child('discover'); const businessRef=rootRef.child('businesses'); 函数getDiscoverBarCont
$范围中的数据ng repeat
。发现
我使用以下代码填充该范围:
`
const businessKey='-KQ1hFH0qrvKSrymmn9d';
const rootRef=firebase.database().ref();
const discoverRef=rootRef.child('discover');
const businessRef=rootRef.child('businesses');
函数getDiscoverBarContent(键,cb){
discoverRef.child(key).on('child_added',snap=>{
让businessRef=businessRef.child(snap.key);
业务参考一次(“价值”,cb);
});
}
getDiscoverBarContent(businessKey,snap=>{
console.log(snap.val());
$scope.discover=snap.val();
});`
然后是一个简单的ng重复:
`{{item.name}`
但是,这不起作用,并返回一行代码:困惑:是否知道我哪里出了问题?我很接近,但需要创建一个空的发现数组,并将快照结果推送到该范围数组。请参见下面的修改代码:
$scope.discover = [];
const businessKey = $scope.finalItem.$id;
const rootRef = firebase.database().ref();
const discoverRef = rootRef.child('discover');
const businessRef = rootRef.child('businesses');
function getDiscoverBarContent(key, cb) {
discoverRef.child(key).on('child_added', snap => {
let businesRef = businessRef.child(snap.key);
businesRef.once('value', cb);
});
}
getDiscoverBarContent(businessKey, snap => {
var snapVal = snap.val();
$scope.discover.push(snapVal);
});
此解决方案不是实时更新,因为这需要更复杂的操作,如Firebase句柄等
$scope.discover = [];
const businessKey = $scope.finalItem.$id;
const rootRef = firebase.database().ref();
const discoverRef = rootRef.child('discover');
const businessRef = rootRef.child('businesses');
function getDiscoverBarContent(key, cb) {
discoverRef.child(key).on('child_added', snap => {
let businesRef = businessRef.child(snap.key);
businesRef.once('value', cb);
});
}
getDiscoverBarContent(businessKey, snap => {
var snapVal = snap.val();
$scope.discover.push(snapVal);
});