gpt4 book ai didi

Angular 2 angular-cli AOT 在模块中声明抽象类?

转载 作者:太空狗 更新时间:2023-10-29 16:56:38 25 4
gpt4 key购买 nike

我正在尝试使用 angular-cli 进行 AOT 编译设置。我有一个从抽象类继承的指令,但在编译期间出现错误,angular 无法确定抽象类属于哪个模块。我无法将它添加到 NgModule 的声明数组中,那么正确的做法是什么?我的代码结构是这样的,

//...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 in Cannot determine the module for class TutorialDirective in /test-app/src/app/tutorial/directive/tutorial.directive.ts!

我的应用模块:

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

好的,经过一些调试后,如果我让它不抽象并将其添加到声明中,它就可以工作。这是否意味着我不能将类标记为抽象类?这似乎不对……

最佳答案

从抽象类中删除 @Component 装饰器,将其替换为 @Injectable() 装饰器。

关于Angular 2 angular-cli AOT 在模块中声明抽象类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41684254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com