firebase не принимает значение из $scope

Я использую firebase и plain angularjs. Когда я пытался получить некоторое значение из $scope и установить его в качестве параметра проверки это не работает и вызывает ошибку

FIREBASE WARNING: Exception was thrown by user callback. Error: Firebase.DataSnapshot.hasChild failed: First argument was an invalid path: "234". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"
at Error (native)
at Xf (https://cdn.firebase.com/js/client/2.2.4/firebase.js:133:59)
at S.Ha (https://cdn.firebase.com/js/client/2.2.4/firebase.js:197:315)
at http://localhost/sriram/Copy%20of%2004-05-2016/js/app.js:75:23
at c (https://cdn.firebase.com/js/client/2.2.4/firebase.js:227:65)
at https://cdn.firebase.com/js/client/2.2.4/firebase.js:49:642
at Cb (https://cdn.firebase.com/js/client/2.2.4/firebase.js:46:165)
at yb (https://cdn.firebase.com/js/client/2.2.4/firebase.js:22:216)
at zb (https://cdn.firebase.com/js/client/2.2.4/firebase.js:21:1259)
at Kh.h.Gb (https://cdn.firebase.com/js/client/2.2.4/firebase.js:203:287) 
firebase.js:133 Uncaught Error: Firebase.DataSnapshot.hasChild failed: First argument was an invalid path: "234". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"

мой код :

$scope.signIn = function()  {
    var primarynumber = $scope.primary_number;
    signInrefTwo = signInref.push();
    console.log($scope.signin_name);
    users = signInref;
      var username =primarynumber;
    users.once('value', function(snapshot) {
    if (!snapshot.hasChild(username)) {
        users.child(username).set({ name: username });
    }
        else {
        alert("That user already exists");
        }
    });


    console.log();

}

Мой рабочий код :

 $scope.signIn = function()  {
    var primarynumber = '123456789';
    signInrefTwo = signInref.push();
    console.log($scope.signin_name);

Пусть я узнаю причину этого. Я попытался утешить $ scope.primary_number и возвращает значение правильно.

1 ответ

  1. мы должны добавить .toString() для VAR, который вы назначаете

    var username = primarynumber.toString(); // it has to be done all the time