Dưới đây là mã ban đầu của tôi để tạo động mô-đun:Angular2: Năng động, sáng tạo thành phần: AOT Compilation
protected createComponentModule(componentType: any) {
@NgModule({
imports: [
ComponentModule
],
declarations: [
componentType
],
})
class RuntimeComponentModule {
}
return RuntimeComponentModule;
}
Trong khi tôi sẽ thực hiện AOT vào mã bên dưới nó ném cho tôi lỗi:
No NgModule metadata found for 'RuntimeComponentModule'
Tôi đã tìm thấy giải pháp của nó một số Articals bằng cách thay đổi bên dưới mã và lỗi của tôi biến mất:
default class RuntimeComponentModule
{
}
Nhưng mới lỗi được nâng lên nó nói:
Modifiers cannot appear here
Nó không cho phép tôi để trang trí @NgModule trong phương pháp.
Bạn có thể tham khảo liên kết này. http://stackoverflow.com/questions/38888008/how-can-i-use-create-dynamic-template-to-compile-dynamic-component-with-angular –
@Karan: không may mắn, tôi đã thử nó –
@Karan Patel, Đã giới thiệu liên kết này. nhưng với AOT nó không hoạt động. – Darshita