2016-10-17 8 views
0

Ich erstelle eine dynamische Vorlage URL mit dem folgenden Code How to use variable to define templateUrl in Angular2, aber ich brauche einen Datepicker in der Vorlage und ich hatte Probleme, die Angular UI Bootstrap Bibliothek hinzuzufügen (Angular 2 Version). Der Fehler istDynamic templateURL mit Angular 2 Version der Angular UI Bootstrap Bibliothek

"Kein Anbieter für NgbDateParserFormatter"

I NgbModule und FormsModule den Abschnitt Einfuhren hinzugefügt

@NgModule({ 
    imports: [CommonModule, NgbModule.forRoot(), FormsModule ], 
    declarations: [DynamicHtmlComponent] 
}) 

class DynamicHtmlModule {} 

Ich habe eine Plunker Version https://plnkr.co/edit/kWoSTi?p=preview Wenn das Feld Datum in der Datei src/articles/first.html ist unkommentiert, die Anwendung funktioniert nicht.

Antwort

0

würde ich die folgende Art und Weise nutzen, es zu tun arbeiten:

this.compiler.compileModuleAndAllComponentsAsync(DynamicHtmlModule) 
    .then(factory => { 
    const moduleRef = factory.ngModuleFactory.create(this.vcRef.parentInjector); 

    const compFactory = factory.componentFactories 
     .find(x => x.componentType === DynamicHtmlComponent); 

    const cmpRef = this.vcRef.createComponent(compFactory, 0, moduleRef.injector); 
}); 

Plunker Example

Eine Anmerkung: Sie NgbDatepickerModule statt NgbModule verwenden können. Es wird die Leistung verbessern Plunker

0

Sie NgbDatepickerModule auf diese Weise importieren:

@NgModule({ 
imports: [ 
    ... 
    NgbDatepickerModule.forRoot() 
], 

Dies sollte die "No-Provider für NgbDateParserFormatter" fix