似乎我陷入了困境,如果我不尝试使用要导出的抽象组件来使运行时应用程序能够扩展,则陷入困境。
@Component({
templateUrl: './abstract-type-ahead.component.html',
styleUrls: ['./abstract-type-ahead.component.scss']
})
export abstract class AbstractTypeAheadComponent<T> implements AfterViewInit {
protected abstract service: AbstractTypeAheadService<T>;
abstract placeholder = 'Type to filter';
formControl = new FormControl();
filteredOptions$: Observable<T[]> = of();
ngAfterViewInit(): void {
this.filteredOptions$ = this.service.bindToLookupQuery(this.formControl);
}
}
如果将组件添加到模块的声明中,则可能由于它是抽象的,所以不允许这样做。如果未添加,则编译器会抱怨说该组件没有模块。
------------------------------------------------------------------------------
Building entry point 'shared-modules'
------------------------------------------------------------------------------
Compiling TypeScript sources through ngc
ERROR: Cannot determine the module for class AbstractTypeAheadComponent in C:/_dev/workspace/projects/shared-modules/src/lib/pattern-library/layout/type-ahead/abstract-type-ahead.component.ts! Add AbstractTypeAheadComponent to the NgModule to fix it.