Angular2 : Dynamic component creation : AOT Compilation
Asked Answered
G

1

11

Below is my initial code to create dynamic module:

protected createComponentModule(componentType: any) {

    @NgModule({
        imports: [
            ComponentModule 
        ],
        declarations: [
            componentType
        ],
    })
    class RuntimeComponentModule {
    }
    return RuntimeComponentModule;

}

While I am going to implement AOT on below code it throw me error:

No NgModule metadata found for 'RuntimeComponentModule'

I found solution of it some Articals by change below code and my error gone away:

default class RuntimeComponentModule 
{
}

But new error is raised it say:

Modifiers cannot appear here

It not allowed me to decorate @NgModule within method.

Glamorous answered 2/3, 2017 at 9:24 Comment(4)
You can refer this link. #38888508Loreenlorelei
@Karan: no luck, I have already tried itGlamorous
@Karan Patel , Already referred this link. but with AOT it's not working.Reporter
check the readme here: https://github.com/laco0416/ng-dynamicStartle
H
1

Using dynamic component or module creation is currently not officially supported to be used together with AoT

See the discussion at https://github.com/angular/angular/issues/11780 for possible workarounds.

Herbalist answered 6/3, 2017 at 7:8 Comment(1)
I also think so, I have already tried so many ways but no luckGlamorous

© 2022 - 2024 — McMap. All rights reserved.