I want to update the data in a table which displays Firebase database.
Each line in the table represents one particular user's data. My goal is to be able to update the data in one field of a user data. In this example, I am trying to change the user role based on a checkbox ng-true-value="'admin'" ng-false-value="'user'"
.
How can I get the user id of the line I am editing/updating the info and pass it into the update function? currently the code is taking the current user ID.
the function I use it update user info is:
$scope.updateRole= function () {
var updated_user_info= {
role: $scope.user.role
};
var myuser = firebase.auth().currentUser;//change this part?!
DatabaseRef.ref('users/' + myuser.uid).update(updated_user_info)
.then(function () {
console.log("update success");
}).catch(function (error) {
$scope.errMsg = true;
$scope.errorMessage = error.message;
});
}
the html view:
<tr ng-repeat="obj in $data">
<td data-title="'First Name'" filter="{ 'First Name': 'text' }" sortable="'firstName'">{{ obj.firstName }}</td>
<td data-title="'Last Name'" filter="{ 'Last Name': 'text' }" sortable="'lastName'">{{ obj.lastName }}</td>
<td data-title="'Role'" filter="{ 'Role': 'text' }" sortable="'role'">
<input type="checkbox" ng-model="user.role" ng-true-value="'admin'" ng-false-value="'user'" ng-click="updateRole()">
{{obj.role}}
</td>
</tr>
currently it is updating only the current user, and also maintaining a checked value for all users, but not updating, only the current user itself.