javascript - Create new item with custom title instead of ID in firebase via Angular -


i'm doing end via angular , using firebase db.

it's working great, , i've create controller create new pots - works perfectly.

however, when creating new post, give in firebase long , random id.

.controller("videosctrl", function(firebase, $scope, $firebasearray) {   var ref = firebase.database().ref('posts')  $scope.groups = $firebasearray(ref); $scope.addgroup = function() { $scope.groups.$add({   title: $scope.newgrouptitle,   caption: $scope.newgroupcaption,   creator: $scope.newgroupcreator,   privacy: $scope.newgroupprivacy,   published: $scope.newgrouppublished,   })  } 

i'm using scope create new pots, i'd instead of having random id have title

      title: $scope.newgrouptitle, 

so db when create post like:

--mydomain ---- posts ------ random id generated --------title --------caption --------creator --------privacy --------published ------ random id generated --------title --------caption --------creator --------privacy --------published ----users 

i'd instead have:

--mydomain ---- posts ------ title ( same below) --------title  --------caption --------creator --------privacy --------published ------ title (same below) --------title --------caption --------creator --------privacy --------published ----users 

any recommendation amazing !

thanks guys !

when use $add in firebase automatically create push id. if want use custom id's. instead should use object.child(id).set(objectinfo);.

i've modified code below:

$scope.addgroup = function() {    $scope.groups.$ref().child($scope.newgrouptitle).set({     title: $scope.newgrouptitle,     caption: $scope.newgroupcaption,     creator: $scope.newgroupcreator,     privacy: $scope.newgroupprivacy,     published: $scope.newgrouppublished  }); } 

this pure javascript code should work since angularfire built on top of javascript library.

one thing note here is better use $firebaseobject instead of $firebasearray when want use custom keys storing objects in firebase.

reference: angularfire issue on github.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -