Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 angular-cli AOT declare abstract class in module?

I'm trying to get AOT compilation setup with angular-cli. I've got a directive that inherits from an abstract class, and I'm getting an error during compilation that angular can't determine what module the abstract class belongs to. I can't add it to the declarations array of the NgModule, so what's the right way to go about this? 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.
}

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 { }

Ok after some debugging, if I make it not abstract and add it to declarations it works. Does this mean I can't mark a class as abstract? That doesn't seem right...

like image 291
Steveadoo Avatar asked Jan 16 '17 20:01

Steveadoo


1 Answers

Remove the @Component decorator from the abstract class, replacing it with an @Injectable() decorator.

like image 175
Velter Avatar answered Oct 19 '22 23:10

Velter