javascript - Edit Item from Firebase -
this sort of follow-up previous question. i'm trying figure out how edit existing item stored in firebase. items repeated on page, , each of them have "edit" button next them.
html
<h3>editing {{ editedprovider.title }}</h3> <form> <input ng-model="editedprovider.title"> <button type="submit" ng-click="updateprovider()">submit</button> </form> <div ng-repeat="provider in providers"> <h3>{{ provider.title }}</h3> <button type="button" ng-click="seteditedprovider()">edit</button> </div> </div>
this how i'm adding item list:
js
var rootref = new firebase(fburl); var providersref = rootref.child('providers'); $scope.newprovider = {}; $scope.providers = []; providersref.on('child_added', function(snapshot) { $timeout(function() { var snapshotval = snapshot.val(); console.log(snapshotval); $scope.providers.push({ title: snapshotval.title, name: snapshot.name() }); }); }); $scope.createprovider = function() { var newprovider = { title: $scope.title }; providersref.push(newprovider); };
i've created function seteditedprovider
, binded edit button, when clicked brings edit form particular item. when i've made changes however, need run function called updateprovider
, , i'm having problems creating function.
$scope.editedprovider = null; $scope.seteditedprovider = function(provider) { $scope.editedprovider = angular.copy(provider); } $scope.updateprovider = function(provider) { // need take edited function , push updated version inside here }
can utilise firebase's data snapshot this, creating item?
some of clicking me, think understand how needs done, can't work out how achieve it.
any problem appreciated. in advance!
$scope.updateprovider = function(provider) { providersref.child(provider.$id).update({tile:provider.title}); }
Comments
Post a Comment