angular - 在 Angular 和 Ng-Bootstrap 中清除 NgbModal 状态
问题描述
成功更新后如何清除模态?当更新出现错误时,我会在模式上显示错误。我只是在成功更新后进行form.reset
。this.modalReference.close()
我想知道如何清除状态,以便当我再次打开模式时,错误将不再存在。
组件.ts
updateUser() {....
if (result.value) {
......subscribe(() => {
form.reset();
this.modalReference.close();
}, err => {
console.log(err);
this.errors = err.error;
});
}
}
组件.html
<app-error [errors]="errors"></app-error>
<tr>.....
error.component.ts
export class ErrorsComponent {
formattedErrors: Array<string> = [];
@Input()
set errors(errorList: Errors) {
this.formattedErrors = [];
if (errorList.errors) {
for (const field of Object.keys(errorList.errors)) {
this.formattedErrors.push(`${field} ${errorList.errors[field]}`);
}
}
};
get errorList() { return this.formattedErrors; }
}
解决方案
我认为你弄错了@Input 装饰器。@Input 装饰器用于从父组件获取数据/输入。就是这样。
// child.component.ts
@Input()
errors: string[];
// parent.component.ts
<child [errors]="my error varialbe in parent component"></child>
推荐阅读
- sql - SQL查询多次加入smae表
- lambda - 使用 java 流对具有相同 ID/名称的对象进行分组
- sql - 软删除和恢复关联表记录
- mysql - 无法识别的语句类型。(靠近 REVOKE)在 MYSQL
- angular - ng build -prod --output-hashing none 有什么用?
- python - 在 Pandas groupby 中显示较低的级别
- java - ArrayList 方法逻辑问题
- javascript - Multer 没有上传,但它不会给我任何错误
- branch-prediction - gem5中查看分支预测器的参数
- php - 如何使用 Firebase 中的用户身份验证更改 Laravel 中的 User::Model