Skip to content

Commit e1dc7e6

Browse files
committed
fix: annotate a couple base classes with @directive for Ivy
There are two base classes in Material/CDK which are intended to be extended by user code: BasePortalHost and MatFormFieldControl. This commit annotates them with `@Directive`. The best way to do this is to use `@Directive()` but this is not supported by Angular 8.x, on which Material and the CDK still depend. Therefore, a workaround is used with a selector which will never be matched. Modules are also added to satisfy the View Engine compiler.
1 parent 20f6eb9 commit e1dc7e6

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/cdk/portal/portal.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
EmbeddedViewRef,
1515
Injector,
1616
ComponentFactoryResolver,
17+
Directive,
18+
NgModule,
1719
} from '@angular/core';
1820
import {
1921
throwNullPortalOutletError,
@@ -179,6 +181,13 @@ export type PortalHost = PortalOutlet;
179181
* Partial implementation of PortalOutlet that handles attaching
180182
* ComponentPortal and TemplatePortal.
181183
*/
184+
@Directive({
185+
// The @Directive with selector is required here because the CDK is still based on Angular 8.x.
186+
// In Angular 9.x, `@Directive()` without any selector is legal (and `BasePortalModule` is not
187+
// necessary either).
188+
// TODO(alxhub): convert to a selectorless Directive when the CDK upgrades to Angular 9.
189+
selector: 'abstract-base-portal-outlet',
190+
})
182191
export abstract class BasePortalOutlet implements PortalOutlet {
183192
/** The portal currently attached to the host. */
184193
protected _attachedPortal: Portal<any> | null;
@@ -260,6 +269,13 @@ export abstract class BasePortalOutlet implements PortalOutlet {
260269
}
261270
}
262271

272+
// TODO(alxhub): remove when `BasePortalOutlet` becomes a selectorless Directive.
273+
@NgModule({
274+
declarations: [BasePortalOutlet as any],
275+
})
276+
export class BasePortalOutletModule {
277+
}
278+
263279
/**
264280
* @deprecated Use `BasePortalOutlet` instead.
265281
* @breaking-change 9.0.0

src/material/form-field/form-field-control.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
*/
88

99
import {Observable} from 'rxjs';
10+
import {Directive, NgModule} from '@angular/core';
1011
import {NgControl} from '@angular/forms';
1112

1213

1314
/** An interface which allows a control to work inside of a `MatFormField`. */
15+
@Directive({
16+
// The @Directive with selector is required here because Material is still based on Angular 8.x.
17+
// In Angular 9.x, `@Directive()` without any selector is legal (and `MatFormFieldControlModule`
18+
// is not necessary either).
19+
// TODO(alxhub): convert to a selectorless Directive when Material upgrades to Angular 9.
20+
selector: 'abstract-mat-form-field-control',
21+
})
1422
export abstract class MatFormFieldControl<T> {
1523
/** The value of the control. */
1624
value: T | null;
@@ -67,3 +75,10 @@ export abstract class MatFormFieldControl<T> {
6775
/** Handles a click on the control's container. */
6876
abstract onContainerClick(event: MouseEvent): void;
6977
}
78+
79+
// TODO(alxhub): remove when `MatFormFieldControl` becomes a selectorless Directive.
80+
@NgModule({
81+
declarations: [MatFormFieldControl as any],
82+
})
83+
export class MatFormFieldControlModule {
84+
}

0 commit comments

Comments
 (0)