Catalin
Catalin

Reputation: 258

Angular-firebase. Data is not inserted correctly

I want my data to be inserted in firebase like so :

cities:{
    Tokyo:{
        name: "Tokyo, JP"
    }
    London:{
        name: "London, UK"
    }

    and so on...

I inserted some data manually from the online GUI : cities

But unfortunately it gets inserted so : minsk

My code

the Firebase factory:

export default function CitiesFactory($firebaseArray, Firebase) {
    'ngInject';
    var ref = new Firebase("https://name.firebaseio.com/");
    return $firebaseArray(ref.child('cities'));
}

Controller (add function):

    $scope.addoras = function(city) {
        CitiesFactory.$add({
            city: {
                name: city
            }
        }).then(function(CitiesFactory) {
            var id = CitiesFactory.key();
            console.log('Added Contact ' + id);
            $scope.addorasmodel = '';

        });
    };

Can someone help me?

Upvotes: 2

Views: 61

Answers (1)

André Kool
André Kool

Reputation: 4968

When you use $add() it will generate a unique push id as it says in the documentation.

If you want to avoid these unique id's you can use set() or update() (Documentation)

var ref = new Firebase("https://name.firebaseio.com/");
ref.set({
    city: {
        name: city
    }
});

var ref = new Firebase("https://name.firebaseio.com/");
ref.update({
    city: {
        name: city
    }
});

Upvotes: 2

Related Questions