我也是 angular 和 firebase 的新手,所以我很难用 firebase 承诺数据填充我的表单。是的,我也很难理解如何处理 promise 与 observables。我会感谢任何帮助。
ngOnInit() {
this.form = this.fb.group({
'email': ['', [ Validators.required,
Validators.pattern('^[a-z]+[a-z0-9._]+@[a-z]+\.[a-z.]{2,5}$')]],
'name': ['', [ Validators.required, Validators.minLength(8)]],
'country': ['', [ Validators.minLength(8)]],
'state': ['', [ Validators.minLength(8)]],
'city': ['', [ Validators.minLength(8)]],
'sexualOpt': ['', [ Validators.minLength(8)]],
'marital': ['', [ Validators.minLength(8)]],
'dateOfBirth': ['', [ Validators.minLength(8)]],
'noChildren': ['', [ Validators.minLength(8)]],
'schoolar': ['', [ Validators.minLength(8)]]
});
this.readProfile() ;}
readProfile() {
firebase.database().ref( 'User/' + 'xs9XP4Aq2aVt0q5CkCuocrYyHwC3' + '/profile' )
.once('value')
.then (function(snapshot) {
this.form.controls['name'].setValue(snapshot.val().name);
console.log(snapshot.val());
});
;}
控制台显示:错误:访问属性“拒绝”的权限被拒绝
问候