Skip to content

fix(form): connect formGroup input not mapped to connect base #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/form/src/connect/connect-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ConnectBase implements OnDestroy, AfterContentInit {
}
@Input() connect?: () => (string | number) | (string | number)[];
protected store?: FormStore;
protected form: any;
protected formGroup: any;
private stateSubscription?: Unsubscribe;

private formSubscription?: Subscription;
Expand All @@ -70,7 +70,7 @@ export class ConnectBase implements OnDestroy, AfterContentInit {
}

Promise.resolve().then(() => {
this.formSubscription = (this.form.valueChanges as any)
this.formSubscription = (this.formGroup.valueChanges as any)
.pipe(debounceTime(0))
.subscribe((values: any) => this.publish(values));
});
Expand Down Expand Up @@ -106,13 +106,15 @@ export class ConnectBase implements OnDestroy, AfterContentInit {

return pairs.filter(p => {
const parent = (p.control as any)._parent;
return parent === this.form.control || parent === this.form;
return parent === this.formGroup.control || parent === this.formGroup;
});
}

private resetState() {
const formElement =
this.form.control === undefined ? this.form : this.form.control;
this.formGroup.control === undefined
? this.formGroup
: this.formGroup.control;

const children = this.descendants([], formElement);

Expand All @@ -129,7 +131,7 @@ export class ConnectBase implements OnDestroy, AfterContentInit {

private publish(value: any) {
if (this.store) {
this.store.valueChanged(this.path, this.form, value);
this.store.valueChanged(this.path, this.formGroup, value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/form/src/connect/connect.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ConnectBase } from './connect-base';
// For template forms (with implicit NgForm)
@Directive({ selector: 'form[connect]:not([formGroup])' })
export class ConnectDirective extends ConnectBase {
constructor(protected store: FormStore, protected form: NgForm) {
constructor(protected store: FormStore, protected formGroup: NgForm) {
super();
}
}