Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is projectableNodes an any[][]?

Tags:

angular

I've played around with

ViewContainerRef.createComponent

and I'm wondering why the parameter projectableNodes is an any[][]. Unfortunatelly, this parameter hasn't been documented so far.

What to pass within this 2D-Array?

Wishes, Manfred

like image 962
Manfred Steyer Avatar asked Dec 29 '16 02:12

Manfred Steyer


1 Answers

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

like image 156
yurzui Avatar answered Sep 28 '22 09:09

yurzui