Reading Firebase data returns client error despite rule being "true"
I am trying to figure out how to do a simple CRUD with angular + firebase. I started with a read operation. I have the following data structure:
With this in mind, I created the following rules:
I have a working factory like this:
factory('wordsFactory', function($http){
var factory = {};
var words = [
{content:"hi", definition:"ooo"},
{content:"h3", definition:"ooo222"}
];
factory.getWords = function(){
return words;
//ajax call here
};
factory.addWords = function(){
//something
}
return factory;
})
I changed it to try and include a call like this:
factory('wordsFactory', function($http){
var factory = {};
var words = [];
var ref = new Firebase('https://my-firebase.firebaseio.com/words');
ref.once('value', function($scope, snapshot) {
$scope.variable = snapshot.val();
words = [
{content: ref.content, definition: ref.definition}
];
});
factory.getWords = function(){
return words;
//ajax call here
};
factory.addWords = function(){
//something
}
return factory;
})
However, when I try to read, I get:
Error: permission_denied: Client doesn't have permission to access the desired data.
and
FIREBASE WARNING: Exception was thrown by user callback. TypeError: Cannot read property 'val' of undefined
Several things, I understand that due to what I have, even if it works, it will only return one value. I'm fine because I just want to figure out how to make it work. I also know that my current data structure could be greatly improved, again I just did this to learn, but feel free to suggest anything you think might help me.
My main problem right now is that I cannot read it. I should also mention that the factory works correctly without firebase, it gets called in the main controller.
source to share
I'm not sure how you arrived at this construction:
ref.once('value', function($scope, snapshot) {
But the callback once
only takes one argument for the event value
. See the related Firebase API documentation .
So, you will have to change it to:
ref.once('value', function(snapshot) {
And find another way to get the scope.
It is recommended to use the simulator tab in your Firebase dashboard to troubleshoot the error. This will usually show you a better explanation of why the operation is being rejected. This detailed information is intentionally not shown to general clients.
source to share