我有基本的Firebase查詢問題,它與其餘的應用程序沒有問題來攜帶數據並與它們一起工作。即使使用Firebase身份驗證。錯誤地訪問查詢的屬性 - AngularJS + Firebase
但是,對於這些查詢,當我嘗試訪問其屬性時返回一個未定義的我。雖然它有明確的定義。
有沒有人看到錯誤?謝謝。
版本與我的工作有:
"dependencies": {
"angular": "^1.5.8",
"bootstrap": "^3.3.7",
"angular-bootstrap": "^2.1.0",
"angularfire": "^2.0.2",
"firebase": "^3.3.2",
"angular-animate": "^1.5.8",
"angular-route": "^1.5.8",
"textAngular": "^1.5.11",
"angular-socialshare": "angularjs-socialshare#^2.3.1",
"angular-timeago": "^0.4.3"
}
這是視圖:
<div ng-controller="blogpostCtrl">
{{post}}
{{post.Title}}
</div>
這是火力的內容:
{
"blog" : {
"posts" : {
"-KT9vxYoCkly93GqTSY7" : {
"CreationDate" : 1475504757165,
"Post" : "<p>esto es una prueba de post</p>",
"Title" : "esto es una prueba",
"Url" : "esto_es_una_prueba",
"isPublished" : true
},
"-KTA-f-BDAzC-4T4a50K" : {
"CreationDate" : 1475505991860,
"Post" : "<p>dsf sdf sdfs fd</p>",
"Title" : "o1i21o3i",
"Url" : "o1i21o3i",
"isPublished" : true
},
"-KTA-ggQSQLnDr4eQtfi" : {
"CreationDate" : 1475505998783,
"Post" : "<p>ds sdf sdf</p>",
"Title" : "4 45654456 2546345562535",
"Url" : "4_45654456_2546345562535",
"isPublished" : true
}
}
}
}
這是控制器:
app.controller("blogpostCtrl", function($scope, $location, $routeParams, $firebaseArray) {
var ref = firebase.database().ref("blog/posts");
$scope.post = $firebaseArray(ref.orderByChild("Url").equalTo($routeParams.uri));
console.log($scope.post)
console.log($scope.post.Title) //<------------ undefined
firebase.database().ref("blog/posts").orderByChild("Url").equalTo($routeParams.uri).once('value').then(function(snapshot) {
console.log(snapshot.val())
console.log(snapshot.val().Title) //<------------ undefined
});
firebase.database().ref("blog/posts").on('value', function(snapshot) {
console.log(snapshot.val())
console.log(snapshot.val().Title) //<------------ undefined
});
});
這是控制檯輸出:
[]0: Object$$added:()$$error:()$$getKey:()$$moved:()$$notify:()$$process:()$$removed:()$$updated:()$add:()$destroy:()$getRecord:()$indexFor:()$keyAt:()$loaded:()$ref:()$remove:()$save:()$watch:()length: 1__proto__: Array[0]
ctrl.js:163 undefined
ctrl.js:170 Object {-KT9vxYoCkly93GqTSY7: Object, -KTA-f-BDAzC-4T4a50K: Object, -KTA-ggQSQLnDr4eQtfi: Object}-KT9vxYoCkly93GqTSY7: Object-KTA-f-BDAzC-4T4a50K: Object-KTA-ggQSQLnDr4eQtfi: Object__proto__: Object
ctrl.js:171 undefined
ctrl.js:166 Object {-KTA-ggQSQLnDr4eQtfi: Object}-KTA-ggQSQLnDr4eQtfi: ObjectCreationDate: 1475505998783Post: "<p>ds sdf sdf</p>"Title: "4 45654456 2546345562535"Url: "4_45654456_2546345562535"isPublished: true__proto__: Object__proto__: Object
ctrl.js:167 undefined
當然這是未定義的。 「標題」是另一個對象的屬性 – Akis
是的,我看到了錯誤,至少在快照的查詢中。但是,當使用$ scope.post = $ firebaseArray(ref.orderByChild(「URL」)equalTo($ routeParams.uri)。);我有這個問題。 此外,我無法獲得一些數據的關鍵,這些數據是我諮詢的。如果我有密鑰,我不會在內部使用字段進行查詢。 – Epifanio