【发布时间】:2019-12-30 05:36:16
【问题描述】:
我有一些代码 ngOnInit 使用路由变量来过滤特定对象的可观察数组:
this.route.paramMap.subscribe(params => { // Wrapper to get route param (ID)
this.store.dispatch(new fromStore.LoadObjects());
this.object$ = this.store.select(fromStore.getAllObjects).pipe(
map(
objects => objects.filter(o => o.id === params.get('id'))[0]
)
);
})
然后我有以下初始化表单:
this.objectDataForm = this.formBuilder.group({
'name': ['', Validators.required ],
'location': ['', Validators.required ]
});
我想以某种方式将我的可观察对象连接到表单数据以作为默认值引入。我想我需要patchValue:
this.objectDataForm.patchValue({
name: myValue1,
location: myValue2
});
但我不知道如何将这个补丁值放在它在正确的时间获取值并将其传递给表单的地方。我可以很容易地对此进行核对...
【问题讨论】:
标签: angular angular-reactive-forms