Angular 2 angular-cli AOT declares an abstract class in a module?

I am trying to configure AOT compilation using angular-cli. I have a directive that inherits from an abstract class, and during compilation I get a message that angular cannot determine which module the abstract class belongs to. I cannot add it to the NgModule declaration array, so is this the right way? My code structure looks like this:

//...imports export abstract class TutorialDirective { //...base class logic } @Directive({ selector: '[tut]', exportAs: 'tut' }) export class DefaultTutorialDirective extends TutorialDirective { //...calls into the base class for some shared stuff. } 

The error looks like this:

 ERROR in Cannot determine the module for class TutorialDirective in /test-app/src/app/tutorial/directive/tutorial.directive.ts! 

My AppModule:

 import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { AppComponent } from './app.component'; import { TutorialService } from './tutorial/tutorial.service'; import { TutorialDirective, DefaultTutorialDirective } from './tutorial/directive/tutorial.directive'; @NgModule({ declarations: [ AppComponent, DefaultTutorialDirective ], imports: [ BrowserModule, FormsModule, HttpModule ], providers: [TutorialService], bootstrap: [AppComponent] }) export class AppModule { } 

Well after some debugging, if I make it non-abstract and add it to the declarations, this works. Does this mean that I can not distinguish the class as abstract? That doesn't seem right ...

+8
angular angular-cli
source share
2 answers

Remove the @Component decorator from the abstract class.

+2
source share

Yes. It’s true that if you create an abstract class and try to use it as a directory controller, this will not work, the reason is in the documentation

Highlight some of the documentation below. enter image description here

When you create a directive, Angular creates a new instance of the directive controller class . When you use an abstract class, you cannot have an instance for it and therefore it fails in your case

0
source share

All Articles