@Directive({
selector: '[connectForm]'
})
export class ConnectFormDirective {
@Input('connectForm') path: string;
constructor(private formGroupDirective: FormGroupDirective,
private store: Store<AppState> ) {
ngOnInit() {
// Update the form value based on the state
this.store.select(state => state.forms[this.path]).take(1).subscribe(formValue => {
this.formGroupDirective.form.patchValue(formValue);
});
}
}
}