Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.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
Javascript 使用userid注册地址_Javascript_Firebase_Firebase Realtime Database - Fatal编程技术网

Javascript 使用userid注册地址

Javascript 使用userid注册地址,javascript,firebase,firebase-realtime-database,Javascript,Firebase,Firebase Realtime Database,我想用userid注册地址。我设法为每个用户添加一个地址。但我的问题是,用户可以有更多的地址 模型 服务地址 saveAdresse(){ firebase.database().ref('adresse/'+ firebase.auth().currentUser.uid).set(this.adresse); } 如果每次调用saveAddresse时都要在用户节点下添加新的地址子节点,则需要调用push,而不是set: saveAdresse(){ firebase.da

我想用userid注册地址。我设法为每个用户添加一个地址。但我的问题是,用户可以有更多的地址

模型

服务地址

saveAdresse(){
    firebase.database().ref('adresse/'+ firebase.auth().currentUser.uid).set(this.adresse);
  }

如果每次调用
saveAddresse
时都要在用户节点下添加新的地址子节点,则需要调用
push
,而不是
set

saveAdresse(){
  firebase.database().ref('adresse/'+ firebase.auth().currentUser.uid).push(this.adresse);
}
每次调用
push
Firebase时,都会生成一个具有唯一ID的新子节点


如果以后要显示特定用户的所有地址,可以使用:

let userAddresses = firebase.database().ref('adresse/'+ firebase.auth().currentUser.uid);
userAddresses.once('value').then((snapshot) => {
  snapshot.forEach((addressSnapshot) => {
    console.log(addressSnapshot.key); // shows the auto-generated ID for each address
    console.log(addressSnapshot.val()); // shows the address value
  })
})

晚上好,谢谢。我可以从控制台恢复,但我看不到地址页上的内容。我有这个错误

地址:address.page.ts

adresse = {} as Adresse;

  constructor(private router: Router) {}

  ngOnInit(){
    let useradresse = firebase.database().ref('adresse/'+ firebase.auth().currentUser.uid);
    useradresse.once('value').then((snapshot) => {
      snapshot.forEach((addressSnapshot) => {
        console.log (addressSnapshot.val()); // shows the address value 
        this.adresse = addressSnapshot.val();
      })
    })

  }
页面html

<ion-content>
    <ion-card *ngFor="let adress of adresse; let i = index" (click)="onViewAdresse(i)">
        <ion-card-content>
            <ion-row>
                <ion-col size="9" >
                        <!--<ion-col size="9" (click)="goTo(adress)">-->
                    <div><b>{{adress.prenom}} {{adress.nom}} </b></div>
                    <div>{{adress.commune}}</div>
                    <div>{{adress.numeroF}}</div>

                </ion-col>
                <ion-col size="3">
                    <div class="color-edit"><b>Modifier</b></div>
                </ion-col>
              </ion-row>
          </ion-card-content>
      </ion-card>

{{address.prenom}}{{address.nom}}
{{地址.公社}
{{address.numeroF}
修饰语
<ion-content>
    <ion-card *ngFor="let adress of adresse; let i = index" (click)="onViewAdresse(i)">
        <ion-card-content>
            <ion-row>
                <ion-col size="9" >
                        <!--<ion-col size="9" (click)="goTo(adress)">-->
                    <div><b>{{adress.prenom}} {{adress.nom}} </b></div>
                    <div>{{adress.commune}}</div>
                    <div>{{adress.numeroF}}</div>

                </ion-col>
                <ion-col size="3">
                    <div class="color-edit"><b>Modifier</b></div>
                </ion-col>
              </ion-row>
          </ion-card-content>
      </ion-card>