angular - проектирование projectableNode для уже существующего компонента ng-содержимого - PullRequest
0 голосов
/ 31 октября 2019

myComp - это компонент с проектируемым содержимым:

@Component({
  selector: 'my-comp',
  template: `
    <div>
      <h1>Component with ng-content</h1>
      <ng-content></ng-content>
    </div>
  `
})
export class myComp {}
constructor(resolver: ComponentFactoryResolver, container: ViewContainerRef) {
  const factory = resolver.resolveComponentFactory(myComp);
  const component = container.createComponent(container);
  // append projectableNodes to component in a later procedure.
}

Есть ли способ добавить projectableNodes к этому компоненту после его инициализации?

Я знаюСуществует непосредственный способ, если они создаются внутри одного аргумента:

const ngContentChildren = [childComp.location.nativeElement, childComp2.location.nativeElement];
const component = container.createComponent(container, 0, undefined, [ngContentChildren]);

Но я надеялся на что-то, что может функционировать, например:

const component = container.createComponent(container);
component.project([children]);

Так что потомки могут быть добавлены позжена

...