Skip to content

Commit

Permalink
fix(ng-core): Fix for "Types of property 'ɵfac' are incompatible."
Browse files Browse the repository at this point in the history
  • Loading branch information
ersimont committed Jan 7, 2021
1 parent 2fe4c91 commit 06f89f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
12 changes: 10 additions & 2 deletions projects/ng-core/src/lib/wrapped-form-control-superclass.spec.ts
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ChangeDetectionStrategy, Component, Injector } from '@angular/core';
import {
ComponentFixtureAutoDetect,
flushMicrotasks,
Expand Down Expand Up @@ -42,7 +42,11 @@ class TestComponent {
providers: [provideValueAccessor(StringComponent)],
changeDetection: ChangeDetectionStrategy.OnPush,
})
class StringComponent extends WrappedFormControlSuperclass<string> {}
class StringComponent extends WrappedFormControlSuperclass<string> {
constructor(injector: Injector) {
super(injector);
}
}

@Component({
selector: `s-date-component`,
Expand All @@ -51,6 +55,10 @@ class StringComponent extends WrappedFormControlSuperclass<string> {}
changeDetection: ChangeDetectionStrategy.OnPush,
})
class DateComponent extends WrappedFormControlSuperclass<Date, string> {
constructor(injector: Injector) {
super(injector);
}

protected innerToOuter(value: string): Date {
return new Date(value + 'Z');
}
Expand Down
18 changes: 13 additions & 5 deletions projects/ng-core/src/lib/wrapped-form-control-superclass.ts
@@ -1,17 +1,22 @@
import { Directive, Injector } from '@angular/core';
import { Injector } from '@angular/core';
import { FormControl } from '@angular/forms';
import { FormControlSuperclass } from './form-control-superclass';

/**
* Extend this when creating a form control that simply wraps an existing form control, to reduce a lot of boilerplate.
* Extend this when creating a form control that simply wraps an existing form control, to reduce a lot of boilerplate. **Warning:** You _must_ include a constructor in your subclass.
*
* Example when you don't need to modify the wrapped control's value:
* ```ts
* @Component({
* template: `<input [formControl]="formControl">`,
* providers: [provideValueAccessor(StringComponent)],
* })
* class StringComponent extends WrappedFormControlSuperclass<string> {}
* class StringComponent extends WrappedFormControlSuperclass<string> {
* // This looks unnecessary, but is required for Angular to provide `Injector`
* constructor(injector: Injector) {
* super(injector);
* }
* }
* ```
*
* Example when you need to modify the wrapped control's value:
Expand All @@ -21,6 +26,11 @@ import { FormControlSuperclass } from './form-control-superclass';
* providers: [provideValueAccessor(DateComponent)],
* })
* class DateComponent extends WrappedFormControlSuperclass<Date, string> {
* // This looks unnecessary, but is required for Angular to provide `Injector`
* constructor(injector: Injector) {
* super(injector);
* }
*
* protected innerToOuter(value: string): Date {
* return new Date(value + "Z");
* }
Expand All @@ -34,8 +44,6 @@ import { FormControlSuperclass } from './form-control-superclass';
* }
* ```
*/
@Directive()
// tslint:disable-next-line:directive-class-suffix
export abstract class WrappedFormControlSuperclass<
OuterType,
InnerType = OuterType
Expand Down

0 comments on commit 06f89f9

Please sign in to comment.