gpt4 book ai didi

Angular 2 警报只显示一次

转载 作者:太空狗 更新时间:2023-10-29 19:29:45 25 4
gpt4 key购买 nike

我有一个 Angular 2 忘记密码组件。该组件要求服务器生成 SMS 验证码,并在 SMS 消息发送时提醒用户。收到服务响应后,会显示一条警报,说明代码已使用 *ngIf 发送到用户的手机。

但是,当用户要求输入第二个代码时,不会弹出警报 (ng2-bootstrap)。

如有任何帮助,我们将不胜感激。

@Component({     
templateUrl:'forgot-password.component.html',
styleUrls:['../../res/styles/login.component.css'],
providers:[{provide:AlertConfig, useFactory:getAlertConfig}]

})
export class ForgotPasswordComponent implements OnInit{


model:any={};
returnUrl:string;
smsCodeResponse:SMSVerificationInfo;
errorMessage:string;
activeVerificationCodeSent:boolean;
constructor(
private route:ActivatedRoute,
private router:Router,
private authenticationService:AuthenticationService
){}


requestVerificationCode(){
this.authenticationService.requestSMSCode(this.model.username)
.subscribe(
(s)=>this.smsCodeResponse=s,
(e)=>this.errorMessage=e,
()=> {
this.activeVerificationCodeSent=this.smsCodeResponse.aktifmi)
};
}

}

模板

<div *ngIf="activeVerificationCodeSent">
<alert type="danger" dismissible="true">
<strong>Bilgi</strong> Doğrulama Kodu telefonunuza gonderildi.
</alert>
</div>

最佳答案

您应该重置 activeVerificationCodeSent在对话框被关闭后为 false。我希望 <alert>被解雇,但你没有重置状态。你应该在你的模板中做这样的事情:

<div *ngIf="activeVerificationCodeSent">**
<alert type="danger" [dismissible]="true" (onClose)="onAlertClose()">
<strong>Bilgi</strong> Doğrulama Kodu telefonunuza gonderildi.
</alert>
</div>

并在你的 ForgotPasswordComponent 中添加一个函数:

onAlertClose(): void {
this.activeVerificationCodeSent = false;
}

关于Angular 2 警报只显示一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42254171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com