如何在AOT编译'无法确定类的模块'时克服错误?

时间:2017-02-01 13:31:39

标签: angularjs angular aot angular2-aot

JIT编译工作正常。但是,我决定使用。编译应用程序 AOT编译。我收到以下错误:

Cannot determine the module for class ProfileComponent 
Cannot determine the module for class ProfileComponent 
Cannot determine the module for class ProfileRESTService

我的应用程序由单个模块组成。同时,它有很多组件和服务。这些在一个@NgModule中描述。变量MODULES包含数组组件和服务,几乎没有@NgModule,只是一个数组类。

modules.ts

...
import {ProfileModule} from './profile/module';

export const MODULES = [
    ...
    ProfileModule
];

简档/ module.ts

...
import {ProfileComponent} from "./component/Profile/index";
import {ProfileRoute} from "./route/ProfileRoute/index";
import {ProfileRESTService} from "./service/ProfileRESTService";

export const ProfileModule = [
    declarations: [
        ...
        ProfileComponent
    ],
    routes: [
        ...
        ProfileRoute
    ],
    providers: [
        ...
        ProfileRESTService
    ]
]

app.module.ts

import {App}   from './app.component';
import {routing} from "./app.routing";
import {MODULES} from "./module/modules";

let moduleDeclaration = {
    declarations: [
       App
    ],
    schemas: [CUSTOM_ELEMENTS_SCHEMA],
    imports: [
        BrowserModule,
        routing,
        FormsModule,
        ReactiveFormsModule,
        HttpModule,
    ]
    bootstrap: [App]
};

for (let module of MODULES) {
    if (!!module['declarations'] && module['declarations'] instanceof Array) {
        for (let item of module['declarations']) {
            moduleDeclaration.declarations.push(item)
        }
    }
    if('routes'){...}
    if('providers'){...}
    if('imports'){...}
}

@NgModule(moduleDeclaration)
export class AppModule {}

我想当AOT编译时,分析在@NgModule中传递的对象,在我的例子中,这个对象还没有准备好。将描述每个模块的应用程序重新编写为@NgModule将很困难。如何使用动态可执行文件moduleDeclaration来解决问题?

0 个答案:

没有答案