Andrey Fedorov
Andrey Fedorov

Reputation: 9689

Why is angularFire example deleting all of my Firebase entries?

I'm trying to get a simple angularFire example working, and am seeing anything I add to my synced Firebase db being immediately deleted. I expected the input box to sync to a string in /items/foo. What am I missing?

Upvotes: 1

Views: 437

Answers (1)

Anant
Anant

Reputation: 7428

angularFire is a little aggressive about removing items that don't match the expected data type. There's discussion about fixing this behavior on Github if you're interested, but you can work around it by explicitly specifying the data type using the 4th argument:

var url = 'https://andreystest.firebaseio.com/items';
angularFire(url, $scope, 'items', '');

The fourth argument is an empty string, which tells angularFire that whatever is stored at the URL is a string. The default model type is an array ([]).

Edit: There seems to be some issues with jsFiddle and Angular. You are missing the ng-app and ng-controller directives which means angular is never initialized. However, even after adding those tags I can't get it to work in jsFiddle, it does work on a regular web page though. Give http://misc.firebase.com/~anant/angular-test.html a try!

Upvotes: 4

Related Questions