Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法设置null javascript错误的属性_Javascript_Angularjs_Typescript - Fatal编程技术网

无法设置null javascript错误的属性

无法设置null javascript错误的属性,javascript,angularjs,typescript,Javascript,Angularjs,Typescript,我不明白为什么我会犯这个错误。有人能帮忙吗。 我可以成功获取快照值。仅当我尝试将true/false分配给此.user\u数据时。我收到此错误:无法将属性“user\u data”设置为null public user_data = false; constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase) { } check_user_exists(number: string){

我不明白为什么我会犯这个错误。有人能帮忙吗。 我可以成功获取快照值。仅当我尝试将true/false分配给此.user\u数据时。我收到此错误:无法将属性“user\u data”设置为null

public user_data = false;


constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase)   {

  }


check_user_exists(number: string){

    const dats = firebase.database().ref('users');

     dats.orderByChild('number').equalTo(number).once("value", function(snapshot){



        if(snapshot.val() !== null){

            this.user_data = true;
            console.log(this.user_data);


        } else {

            this.user_data = false;
            console.log(this.user_data);

        }


    });



}
“this”不是你想象的那样,在javascript
中,this
与其他一些语言不同

要使代码正常工作,请执行以下操作:

 (snapshot) => { 
 // ...
});
而不是

function (snapshot) { ... }
我建议花点时间深入研究一下“”是什么,尽管“this”不是你想象的那样,在javascript中,它与其他一些语言不同

要使代码正常工作,请执行以下操作:

 (snapshot) => { 
 // ...
});
而不是

function (snapshot) { ... }

我建议您花点时间深入研究一下“虽然”是什么

thxx,以获得您的答案。。。来自php背景…你的建议有效!但我还是要深入研究如何使用这个。。这个链接很有用..再次点击:Dthxx获取您的答案。。。来自php背景…你的建议有效!但我还是要深入研究如何使用这个。。这个链接很有用。再次谢谢