firebase不接受$ scope的值

时间:2016-05-04 05:29:21

标签: angularjs scope firebase

我正在使用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 个答案:

答案 0 :(得分:0)

我们必须将.toString()添加到您要分配的var

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