我正在开发AngularJS PWA应用程序(在我的注册组件中有表单)
表格有3个步骤:
第1步
第2步
第3步
当我的用户完成第一步时,我有单选按钮:
<div class="radio">
<label><input type="radio" name="step2" formControlName="step2" value="1"> Fortsæt</label>
<label><input type="radio" name="step2" formControlName="step2" value="2"> Ring mig op</label>
</div>
代码:
this.rForm.get('step2').valueChanges.subscribe(
(step2) => {
// here I have user registration width angularfire2
this.afAuth.auth.createUserWithEmailAndPassword(email, password).then(function(user) {
}
});
当用户单击单选按钮之一时,此代码将在firebase中注册用户,但如果用户再次单击第二个单选按钮,代码将再次尝试注册用户,我的控制台出现错误(电子邮件已经退出..) 。
这是什么解决方案?我想只注册用户第一次触摸单选按钮。我不是在这里提交,因为我有另外的字段和步骤。我只希望注册用户第一步。
答案 0 :(得分:1)
您可以使用first
或take
运算符
import 'rxjs/add/operator/first';
this.rForm.get('step2').valueChanges.first().subscribe(
this.rForm.get('step2').valueChanges.take(1).subscribe(