javascript - 如何以角度启用佐罗模式中的保存按钮
问题描述
TS
generateForm() {
const passwordForm = {
password: [null, [Validators.required, Validators.minLength(8)]],
newPassword: [null, [Validators.required, Validators.minLength(8)]]
};
if (this.user) {
passwordForm['username'] = [this.user];
} else {
passwordForm['old'] = [null, [Validators.required]];
}
return this.formBuilder.group(passwordForm);
}
generateContainer() {
const _this = this;
this.modalRef = this.modalService.create({
nzTitle: this.translate.instant('Change Password'),
nzContent: this.modalForm,
nzOkText: 'Save',
nzOkDisabled: !this.formGroup.valid,
nzOnOk: () => {
_this.returnPassword(true);
_this.modalRef.destroy();
},
nzOnCancel: () => {
_this.returnPassword(false);
_this.formGroup.reset();
_this.modalRef.destroy();
}
});
}
HTML
<ng-template #modalForm>
<form nz-form [formGroup]="formGroup">
<ng-container *ngIf="!user" [ngTemplateOutlet]="currentUser"></ng-container>
<ng-template #currentUser>
<nz-form-item>
<nz-form-label nzFor="old">
<span translate>Old Password</span>
</nz-form-label>
<nz-form-control>
<input nz-input name="old" type="password" id="old" autocomplete formControlName="old"
[placeholder]="'Enter Old Password' | translate" />
<nz-form-explain *ngIf="formGroup.get('old')?.dirty && formGroup.get('old')?.errors">
<span translate>Old password is required!</span>
</nz-form-explain>
</nz-form-control>
</nz-form-item>
</ng-template>
<nz-form-item>
<nz-form-label nzFor="password">
<span translate>New Password</span>
</nz-form-label>
<nz-form-control>
<input nz-input name="password" type="password" id="password" autocomplete formControlName="password"
[placeholder]="'Enter New Password' | translate" />
<nz-form-explain *ngIf="formGroup.get('password')?.dirty && formGroup.get('password')?.errors">
<span translate *ngIf="formGroup.get('password')?.value.length === 0">Password is required!</span>
<span translate *ngIf="formGroup.get('password')?.value.length > 0">Minimum of 8 characters!</span>
</nz-form-explain>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label nzFor="newPassword">
<span translate>Confirm New Password</span>
</nz-form-label>
<nz-form-control>
<input nz-input name="newPassword" type="password" id="newPassword"
[placeholder]="'Confirm New Password' | translate" formControlName="newPassword" autocomplete />
<nz-form-explain *ngIf="
(formGroup.get('newPassword')?.dirty && formGroup.get('newPassword')?.errors) ||
(formGroup.get('password')?.valid &&
formGroup.get('password')?.value !== formGroup.get('newPassword')?.value)
">
<span translate>Password did not match!</span>
</nz-form-explain>
</nz-form-control>
</nz-form-item>
</form>
</ng-template>
我在这里要做的是启用保存按钮。但是当我运行应用程序并填写所有字段时,它没有启用保存按钮,它仍然被禁用。新密码和确认新密码匹配。按钮仍然被禁用。
填写完所有字段后如何启用保存按钮?
解决方案
推荐阅读
- google-sheets - 比较 sheet1 中 sheet2 中缺失的行,并在 sheet3 中显示它们的条件
- javascript - 如何在 Webpack 中覆盖惰性 import() 解析
- python - 将系列转换为二维数组
- python - 无在 Python 编码中导致分组方法
- python - 如何获取不包括特定 RGB 值的区域的边界框
- python-3.x - Seaborn中分类xaxis的更改顺序
- apache - 如何阻止垃圾邮件机器人使用 htaccess 访问网站?
- excel - 获取每月更改位置的多个单元格值
- openshift - 什么组件正在解析 OpenShift 路由器中的域
- python - 修复 INIT AND QUIT 的 no 模块后,我的 Vs pygame 仍然不显示突出显示