AngularFire Single Update Object

How to update a single object in node.

{ 
 foo: 
  {
   title: 'hello world', 
   time: '1000'
  } 
}

As above, I just want the update header. $firebase(new Firebase(ref).child('foo')).$save();will update the entire node. Also tried $save('title'), but did not work.

The reason I just want to update a single object is because some of the ng models do not need to be updated to firebase.

+4
source share
2 answers

Here is an example pointing the heading to "everything"

$firebase(new Firebase(ref)).$child('foo').$child('title').$set("whatever")
+3
source

I recently worked with corner fire and firebase. I am not sure if this is a fix, but I donโ€™t think you need to explicitly select the property of the element that you want to update when using the $ save () method.

, init,

HTML

<ul ng-repeat="user in vm.users>
    <button ng-click="vm.updateUserInit(user)">Edit</button>
</ul>

. $firebaseObject.

var selectedUser;

vm.updateUserInit = function (user) {
        var ref = new Firebase("https://<foo>.firebaseio.com/users/" + user.$id);
        selectedUser = $firebaseObject(ref);
}

firebase selectedUser $save.

,

HTML

<button type="button" ng-click="vm.updateUserDetails()">Update User Details</button>

, . , , .

vm.updateUserDetails = function () {
   selectedUser.firstName = vm.firstName;
   selectedUser.$save();
 }

selectedUser.$save(); , 6

, , . valcon, . firebase

2

,

 constructor(private db: AngularFireDatabase) {}

 update(fbPath: string, data: any) {
     return this.db.object(fbPath).update(data);
 }

 this.api.update(`foo`, ({ title: 'foo Title' }) );

+2

Source: https://habr.com/ru/post/1523720/


All Articles