7

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

1 Answer 1

13

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.