我是Ionic2的新手,我自己无法解决一件事,我有一个小的app宽度页面:user-list并从firebase width angularfire2获取数据。
Firebase中的第一个表名是:已导入 Firebase中的第二个表名称是:userProfile
导入表中的是用户详细信息(name,email,bdate等..),我想从该表中获取数据,然后逐个推送到userProfile表。
所以我的user-list.ts是这样的:
export class UsersListPage {
public signupForm: FormGroup;
user:any;
usersList: FirebaseListObservable<any[]>;
usersTable: FirebaseListObservable<any[]>;
constructor(
public navCtrl: NavController,
public formBuilder: FormBuilder,
public navParams: NavParams,
public authProvider: AuthProvider,
public db: AngularFireDatabase
) {
this.usersList = db.list('/imported');
this.usersTable = db.list('usersProfile');
this.user = authProvider.userUid();
this.signupForm = formBuilder.group({
address: [''],
password: [''],
bday: [''],
email: [''],
name: [''],
number: [''],
signedup: [''],
telephone: [''],
zip: [''],
uid: [''],
});
}
createUser(){
this.authProvider.signupUser(this.signupForm.value.email, this.signupForm.value.password).then(() => {
this.usersTable.push({
email: this.signupForm.value.email,
password: this.signupForm.value.password,
address: this.signupForm.value.address,
bday: this.signupForm.value.bday,
name: this.signupForm.value.name,
number: this.signupForm.value.number,
signedup: this.signupForm.value.signedup,
telephone: this.signupForm.value.telephone,
zip: this.signupForm.value.zip,
uid: this.user
});
});
}
}
我的html是:
<ion-content padding>
<form *ngFor="let user of usersList | async" [formGroup]="signupForm" (submit)="createUser()">
<ion-input formControlName="email" value="{{ user.email }}" type="text"></ion-input>
<ion-input formControlName="password" value="{{ user.telephone }}" type="text"></ion-input>
<ion-input formControlName="address" value="{{ user.address }}" type="text"></ion-input>
<ion-input formControlName="bday" value="{{ user.bday }}" type="text"></ion-input>
<ion-input formControlName="name" value="{{ user.name }}" type="text"></ion-input>
<ion-input formControlName="number" value="{{ user.number }}" type="text"></ion-input>
<ion-input formControlName="signedup" value="{{ user.signedup }}" type="text"></ion-input>
<ion-input formControlName="telephone" value="{{ user.telephone }}" type="text"></ion-input>
<ion-input formControlName="zip" value="{{ user.zip }}" type="hidden"></ion-input>
<button ion-button type="submit" color="secondary" >
User Registration
</button>
</form>
</ion-content>
它可以工作但是这里有一个问题,当我点击按钮时只添加导入表中的最后一条记录,所以我不能每次点击添加一个用户