我有一些代码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
});
但我不知道如何将这个修补程序的值放在一个合适的时间获取值并将其传递到表单的位置。我可以轻而易举地把这个…