Why is projectableNodes an any[][]?

后端 未结 1 1895
闹比i
闹比i 2021-01-19 04:14

I\'ve played around with

ViewContainerRef.createComponent

and I\'m wondering why the parameter projectableNodes is an any[][]. Unfortunatelly, this parameter

相关标签:
1条回答
  • 2021-01-19 04:24

    As we can have several ng-content we can pass several array nodes for each of ng-content

    Let's say we have the following dynamic component:

    <ng-content></ng-content>
    <div class="container">
      <div class="sidebar">
          <ng-content></ng-content>
      </div>
      <div class="content">
          <ng-content></ng-content>
      </div>
    </div>
    

    So when we're creating component dynamically we can inject one and more nodes for each of ng-content places:

    this.vcRef.createComponent(factory, this.vcRef.length, null, [
      [document.createTextNode('Top ng-content - Header')],
      [
        document.createTextNode('First ng-content'), 
        document.createElement('br'), 
        document.createTextNode('First ng-content second row')
      ],
      [
        document.createTextNode('Second ng-content'), 
        document.createElement('br'), 
        document.createTextNode('Second ng-content second row')
      ]
    ]);
    

    Plunker Example

    0 讨论(0)
提交回复
热议问题