2

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?

1

1 Answer 1

2

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
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.