Reputation: 1716
In an AngularJS app, I'm trying to get a firebase reference that does exist and I'm following the suggestions of a similar question here.
Now, I've identified the following line in my controller as the culprit:
var indexRef = new Firebase(refString);
it is nestled in a setTimeout() since that seemed to solve another error of undefined. I currently have
refString.replace(/\/|:|#|%|\.|\[|\| ]/g, '');
in order to avoid
Uncaught Error: new Firebase failed: First argument must be a valid firebase URL and the path can't contain ".", "#", "$", "[", or "]".
Here's an instance running live on Heroku and here's the plnkr.
Upvotes: 0
Views: 1609
Reputation: 1716
The answer is not to parse refString with the regex, but to parse location instead.
var refString = baseURL+'/index/domains/'+ location.replace(/\./g, '-');
console.log('refString',refString);
output: refString https://tezt.firebaseio.com/index/domains/run-plnkr-co
refString = a db id on the path https://tezt.firebaseio.com/domains hence the need to parse the host before saving as a db key.
Upvotes: 0
Reputation: 48599
You don't want to replace forward slashes in a url. By the way, you should try to figure out what a regex character class is.
You should have used console.log() to display the result of the replace() to see the url you are actually using for firebase:
var refString = 'https://path/to' + '/index/domains/' + 'other/stuff';
console.log(refString.replace(/\//g, ''));
--output:--
https:somethinghereindexdomainsotherstuff
That url won't work on teh internets. You have to know basic javascript, as well as basic javascript debugging, before trying to learn angular or firebase.
Upvotes: 3