Angularjs 从Firebase中删除特定用户

Angularjs 从Firebase中删除特定用户,angularjs,firebase,firebase-realtime-database,Angularjs,Firebase,Firebase Realtime Database,我尝试制作一个在线数据库(Firebase),用于测试和学习。 我成功地在数据库中添加了成员,但我不知道我的代码在哪里有问题 这是我的密码: <!DOCTYPE html> <html> <head> </head> <body> <button onclick="saveData()">Save Data</button> <button onclick="pr

我尝试制作一个在线数据库(Firebase),用于测试和学习。 我成功地在数据库中添加了成员,但我不知道我的代码在哪里有问题

这是我的密码:

<!DOCTYPE html>
<html>
  <head>


  </head>
    <body>
      <button onclick="saveData()">Save Data</button>
      <button onclick="printData()">Print Data</button>
      <button onclick="printData2()">Print Data2</button>
      <button onclick="remove()">Remove</button>
      <script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
      <script>
        var ref = new Firebase("https://projecttest-9aee9.firebaseio.com/web/saving-data/fireblog");
        var usersRef = ref.child("users");
        function saveData(){
        usersRef.set({
          alanisawesome: {
            date_of_birth: "June 23, 1912",
            full_name: "Alan Turing"
          },
          gracehop: {
            date_of_birth: "December 9, 1906",
            full_name: "Grace Hopper"
          }
        });
      }

      function printData(){

        usersRef.on("value", function(snapshot) {
        console.log(snapshot.val());
      }, function (errorObject) {
        console.log("The read failed: " + errorObject.code);
      });
      }
       function printData2(){

        ref.child("users/gracehop/date_of_birth").on("value", function(snapshot) {
        console.log(snapshot.val());//"December 9, 1906"
      }, function (errorObject) {
        console.log("The read failed: " + errorObject.code);
      });
      }
      var ref = new Firebase("https://projecttest-9aee9.firebaseio.com/web/saving-data/fireblog/users");
      var usersRef= ref.child("users");
      function remove(){
          usersRef.remove({

          .then(function() {
             console.log("Remove succeeded.")
                            })
          .catch(function(error) {
             console.log("Remove failed: " + error.message)
                                 })
        });
        }
      </script>
    </body>
</html>

保存数据
打印数据
打印数据2
去除
var ref=新的火基(“https://projecttest-9aee9.firebaseio.com/web/saving-data/fireblog");
var usersRef=ref.child(“用户”);
函数saveData(){
usersRef.set({
alanisawesome:{
出生日期:“1912年6月23日”,
全名:“艾伦·图灵”
},
gracehop:{
出生日期:“1906年12月9日”,
全名:“格雷斯·霍珀”
}
});
}
函数printData(){
usersRef.on(“值”,函数(快照){
console.log(snapshot.val());
},函数(errorObject){
log(“读取失败:+errorObject.code”);
});
}
函数printData2(){
参考child(“用户/gracehop/出生日期”)。关于(“值”,函数(快照){
console.log(snapshot.val());/“1906年12月9日”
},函数(errorObject){
log(“读取失败:+errorObject.code”);
});
}
var ref=新的火基(“https://projecttest-9aee9.firebaseio.com/web/saving-data/fireblog/users");
var usersRef=ref.child(“用户”);
函数删除(){
usersRef.remove({
.然后(函数(){
log(“删除成功”)
})
.catch(函数(错误){
日志(“删除失败:+错误消息”)
})
});
}
我是新手,我需要你的帮助

谢谢你的关注

删除()的语法错误,承诺的处理方式如下:

usersRef.remove()
  .then(function() {
    console.log("Remove succeeded.")
  })
  .catch(function(error) {
    console.log("Remove failed: " + error.message)
  });
修复后,您需要确保
usersRef
对应于要删除的内容

如果您的用户由Firebase用户ID设置密钥,例如:

 "users" : {
    "8dGTb3sxVCbll" : {
      ...
    },
    "bGIav9o7PhhIB" : {
      ...
    },  
 }
您想将
userRef
设置为类似的值

usersRef = firebase.database().ref(`users/${user.uid}`);
然后简单地做

usersRef.remove()
还有一种可能更干净的方法可以删除用户。从

我不知道您的具体设置,因此您可能需要尝试这两种解决方案。 如果您有问题,请告诉我。

删除()的语法错误,承诺的处理方式如下:

usersRef.remove()
  .then(function() {
    console.log("Remove succeeded.")
  })
  .catch(function(error) {
    console.log("Remove failed: " + error.message)
  });
修复后,您需要确保
usersRef
对应于要删除的内容

如果您的用户由Firebase用户ID设置密钥,例如:

 "users" : {
    "8dGTb3sxVCbll" : {
      ...
    },
    "bGIav9o7PhhIB" : {
      ...
    },  
 }
您想将
userRef
设置为类似的值

usersRef = firebase.database().ref(`users/${user.uid}`);
然后简单地做

usersRef.remove()
还有一种可能更干净的方法可以删除用户。从

我不知道您的具体设置,因此您可能需要尝试这两种解决方案。 如果你有问题,请告诉我