Павел Козловский - Реактивное воспитание с Angular 2 - NG-BE 2016

ел бы установить тело<ng-content> при создании экземпляра компонента динамическиComponentFactoryResolver.

Я вижу, что могу получить доступ к вводу и выводу, используяComponentRef, но не способ установить<ng-content>.

пожалуйста, обратите внимание<ng-content> Я планирую настройку, может содержать простой текст / может охватывать динамически созданные компоненты

@Component({
    selector: 'app-component-to-project',
    template: `<ng-content></ng-content>`
})
export class ComponentToProject implements AfterContentInit {

    ngAfterContentInit() {
        // We will do something important with content here
    }

}


@Directive({
    selector: 'appProjectionMarker'
})
export class ProjectionMarkerDirective implements OnInit {

    constructor(private viewContainerRef: ViewContainerRef, private componentFactoryResolver: ComponentFactoryResolver) {
    }

    ngOnInit() {
        const componentFactory: ComponentFactory<ComponentToProject> = this.componentFactoryResolver.resolveComponentFactory(ComponentToProject);
        const componentRef: ComponentRef<ComponentToProject> = this.viewContainerRef.createComponent(componentFactory);
        // Question: How to set content before the child's afterContentInit is invoked
    }

}

@Component({
    selector: 'appTestComponent',
    template: `<div appProjectionMarker></div>`
})
export class TestComponent {}

Ответы на вопрос(1)

Ваш ответ на вопрос