0
Angular2:建議將ngrx流直接連接到Form的方式?Angular2:建議將ngrx流直接連接到Form的方式?
我檢查了網頁,我能找到的最好的方法是找到最佳做法,將ngrx流連接成反應形式。這是我迄今發現:
@Component({
template: `<dumb-component [form]="form" [data]="data$ | async"></dumb-component>`
})
class SmartComponent {
public data$ = this._store.let(someSelector$());
public form = new FormGroup({
foo: new FormControl(''),
bar: new FormControl('')
});
constructor(private _store: Store<IState>) {}
}
@Component({
template: `
<form [formGroup]="form">
<input type="text" formControlName="foo" />
<input type="text" formControlName="bar" />
</form>
`
})
class DumbComponent {
@Input()
public form: FormGroup;
@Input()
set data(v) {
if (v) {
this.form.patchValue(v);
}
};
}
問候,
肖恩
請在您的問題中編輯關聯問題中推薦的任何練習的示例。 – cartant
我不會將FormGroup作爲參數傳遞給DumbComponent。我會傳遞一個對象並從中創建formGroup。 – cgatian
使用智能和愚蠢的組件是一種方式,但將'FormGroup'傳遞給啞組件看起來有點臭 - 對我來說。 – cartant