【发布时间】:2018-11-26 14:55:47
【问题描述】:
很抱歉打扰你,我已经彻底搜索了这个,但我一直在积极尝试解决这个问题超过 20 小时。我即将放弃使用 angularjs 和 firebase。就是想不通..
我正在尝试将数据库值从数组添加到页面。它适用于其他数据,但不适用于此。
我的 Firebase 数据库: 我已经包含了与 freebets 相关的代码,这些代码都很好,但 bookie 的 deatils 无法正常工作。数组中还有其他 bookie 详细信息,我也将调用它们,只是想让一个工作..
myApp.controller('BetsController',
['$scope', '$rootScope', '$location', '$routeParams', '$firebaseObject', '$firebaseArray',
function($scope, $rootScope, $location, $routeParams, $firebaseObject, $firebaseArray) {
//Values passed throu routeparams are assigned to variables and then used to search the firebase database.
var ref, freeBetList, test;
$scope.whichoffer = $routeParams.oId;
$scope.whichuser = $routeParams.uId;
ref = firebase.database().ref()
.child('users').child($scope.whichuser)
.child('offers').child($scope.whichoffer)
.child('freeBets');
freeBetList = $firebaseArray(ref);
$scope.freeBets = freeBetList;
test = firebase.database().ref()
.child('users').child($scope.whichuser)
.child('offers');
//.child('offerbookie')
// testing = $firebaseObject(test);
testing = $firebaseArray(test);
$scope.test = testing;
<div class="card meetings cf">
<h2>Free Bets</h2>
<div class="meeting" ng-repeat="(key, freeBets) in freeBets">
<a href="#">
<span class="text">{{freeBets.eventname}}</span>
</a>
<button class="btn btn-delete tooltip"
ng-click="deleteOffer(key)"><span>Delete this offer</span></button>
</div>
</div>
<div class="card meetings cf">
<h2>Offer Details</h2>
<div class="meeting" ng-repeat="(key, value) in test">
<a href="#">
<p>{{whichoffer.offerbookie}}</p>
</a>
</div>
</div>
控制台日志:
[]
"$$added": function added()
"$$error": function error()
"$$getKey": function getKey()
"$$moved": function moved()
"$$notify": function notify()
"$$process": function process()
"$$removed": function removed()
"$$updated": function updated()
"$add": function add()
"$destroy": function destroy()
"$getRecord": function getRecord()
"$indexFor": function indexFor()
"$keyAt": function keyAt()
"$loaded": function loaded()
"$ref": function ref()
"$remove": remove()
length: 1
name: "bound $remove"
__proto__: function ()
"$resolved": true
"$save": function save()
"$watch": function watch()
0: Object { date: 1529091671870, offerbookie: "Coral", offermarket: "Betfair", … }
1: Object { date: 1529150480309, offerbookie: "SkyBet", offermarket: "Smarkets", … }
length: 2
__proto__: Array []
bets.js:42:4
我只想显示与$scope.whichoffer 相关的一个offerbookie 值。
电流输出:
【问题讨论】:
-
那么代码的哪一部分不起作用?您可以在控制器代码的最后一行之后执行 console.log(testing) 并在此处发布吗?
-
感谢您的回复 - {{whichoffer.offerbookie}} 我一直在尝试让 offerbookie 的值显示但没有成功。
-
ReferenceError: testing is not defined[了解更多] bets.js:44:2
-
第一次初始化它。喜欢: var testing = $firebaseArray(test); $scope.test = 测试; console.log(testing);
-
首先定义测试然后尝试。
标签: angularjs firebase angularjs-ng-repeat angularfire