0

I found a link regarding dynamically loading of template in Angular 2 component here http://www.bennadel.com/blog/3101-experimenting-with-dynamic-template-rendering-in-angular-2-rc-1.htm.

I am trying to implement this in beta.9 which makes the plunker to break http://plnkr.co/edit/g9Mect63GoaybJmqLMef?p=preview. What are the breaking changes in angular2 rc-1 which makes my plunker not work?

Here is his plunker demo in rc-1 http://plnkr.co/edit/6cwYyfPUJZYOMM5YD1IB?p=preview. I can't spot the error since there are no errors also showing in Console window.

        <dynamic-repeater [items]="colors">
        <template #itemRenderer #color="item" #index="index">
            <div title="Item {{ index }}" class="swatch" [style.backgroundColor]="color.hex">
                <br />
            </div>
            <div class="name">
                {{ color.name }}
            </div>
        </template>
    </dynamic-repeater>
halfer
  • 19,824
  • 17
  • 99
  • 186
abhilash reddy
  • 1,546
  • 8
  • 31
  • 53
  • And you want to make it work in beta.9 or in RC.1? – Günter Zöchbauer Jun 10 '16 at 09:38
  • I want it to work in beta.9 – abhilash reddy Jun 10 '16 at 09:39
  • What's the problem? I don't see an error in any of these two Plunkers. Uh, I guess you want the same behavior. Got it. – Günter Zöchbauer Jun 10 '16 at 09:39
  • In the second plunker you will see the data which is passed as input,i mean i am able to see the div with appropriate color which is passed into the child component but in the first plunker i am not able to see any output – abhilash reddy Jun 10 '16 at 09:42
  • http://stackoverflow.com/questions/36325212/angular-2-dynamic-tabs-with-user-click-chosen-components/36325468#36325468 contains Plunker in a few versions. I don't know if `ViewContainerRef.createXxx` was available this way in beta.15 or even beta.9. – Günter Zöchbauer Jun 10 '16 at 09:43
  • Thanks...viewContainerRef was added as a breaking change in Beta.16... But brother i have a question regarding this dynamic template rendering.How is dynamic template rendering helpful? I mean in the plunker(rc-1 example) i have passed data into the child component and also the format to apply ngFor...What advantage do i have by doing like this... In what situations this kind of approach would be helpful...Any suggestion will be helpful for me brother – abhilash reddy Jun 10 '16 at 09:54
  • When the component you want to add is not known statically. If you can add `` to the template, then there is no need for `ViewContainerRef.createComponent`. I didn't have a very close look at your Plunker but it looks like it is used to create components at runtimer (maybe for user-provided HTML). There is currently no other way to support binding with user-provided HTML. – Günter Zöchbauer Jun 10 '16 at 09:58
  • Ok...Thank you brother – abhilash reddy Jun 10 '16 at 10:02
  • ... and if you just want to allow the user of your component to pass a component to be used in your component (other that just transclution). – Günter Zöchbauer Jun 10 '16 at 10:03

0 Answers0