Angular 如何在打开前在模式内设置被动表单字段?
我已经写了一年多的预约管理系统,在这段时间里,我看到了各种角度的更新,即角度7->角度8->9->现在10 每次更新都会导致一些小的突破性变化,但很容易修复 我不是100%确定,但我认为angular 10的最后一次更新打破了我的模态中的反应形式 有缺陷的角度组件的简要说明: 基本上是一个包含数据表和后端数据库表内容的组件。当用户双击其中一行时,会打开包含反应式表单的模式,以允许用户编辑db记录 我使用以下“打开”功能打开ng引导模式:Angular 如何在打开前在模式内设置被动表单字段?,angular,angular-reactive-forms,reactive-forms,Angular,Angular Reactive Forms,Reactive Forms,我已经写了一年多的预约管理系统,在这段时间里,我看到了各种角度的更新,即角度7->角度8->9->现在10 每次更新都会导致一些小的突破性变化,但很容易修复 我不是100%确定,但我认为angular 10的最后一次更新打破了我的模态中的反应形式 有缺陷的角度组件的简要说明: 基本上是一个包含数据表和后端数据库表内容的组件。当用户双击其中一行时,会打开包含反应式表单的模式,以允许用户编辑db记录 我使用以下“打开”功能打开ng引导模式: open(title:string, code:strin
open(title:string, code:string, desc:string, type:string, message:string, updType:string) {
const modalRef = this.modalService.open(
MediaModalComponent,
{
size: 'xl',
windowClass: 'custom-class'
});
modalRef.componentInstance.title = title;
modalRef.componentInstance.code = code;
modalRef.componentInstance.desc = desc;
modalRef.componentInstance.type = type;
modalRef.componentInstance.message = message;
modalRef.componentInstance.updType = updType;
this.mediaModal.mediaForm.patchValue({
code: code,
desc: desc,
type: type,
message: message
});
modalRef.componentInstance.refreshTable.subscribe(() => {
this.getMediaData();
})
}
不幸的是,patchValue函数似乎不起作用,因为打开模式时我的表单字段为空
在创建新问题之前,我已使用以下来源试图自己找到解决方案:
非常感谢您的帮助。我本想在接下来的几周内让这个应用程序上线,但只注意到了这个bug。我认为问题不在于角度版本和反应形式。Angular2的唯一变化是关于.ts更严格,首先,在subscribe to valueChanges中,res的值与form.value.control和form.get('control')的值不同 我不知道您在那里定义了
this.mediamodel.mediaForm
。你想写信吗
modalRef.componentInstance.mediaForm.pathValue(....)
如果您在ngOnInit中创建表单组,可能需要“等待”来创建表单。这就是使用setTimeout
setTimeout(()=>{
modalRef.componentInstance.mediaForm.pathValue(....)
})