How do you put the template of the repetitive element in the component?



  • I want to pass something like that. ng-content Total ngFor inside my component. But the thing is, I need to transfer the repetitive element to an element that will transcend. //stackoverflow.com/a/32319422/4928642 Something like that for the first angull: http://plnkr.co/edit/aZKFqPJmPlfTVRffB0Cc?p=preview ♪

    How do you do that on the second?

    PS: //stackoverflow.com/q/38466490/4928642



  • This should be used. ngForTemplate:

    https://plnkr.co/edit/mpuQse2QuyP7QHXL7wM1?p=preview

    @Component({
      selector: 'foo',
      template: `
        <h1>I am foo</h1>
        <div>
          <template ngFor [ngForOf]="data" [ngForTemplate]="itemTemplate"></template>
        </div>
      `
    })
    export class Foo {
      @Input() data: any[];
      @ContentChild(TemplateRef) itemTemplate: TemplateRef<any>;
    }
    

    @Component({
    selector: 'my-app',
    template: &lt;h1&gt;Angular 2 Systemjs start&lt;/h1&gt; &lt;foo [data]="items"&gt; &lt;template let-item&gt; &lt;div&gt;item: {{item}}&lt;/div&gt; &lt;/template&gt; &lt;/foo&gt; ,
    directives: [Foo],
    })
    export class AppComponent {
    items = [1, 2, 3, 4];
    }

    Teg template May be replaced by attribution:

    https://plnkr.co/edit/jB4qzx9Zd3JLkyenu9f3?p=preview

    <foo [data]="items">
    <div template="let item">item: {{item}}</div>
    </foo>

    What's the scoop that's got a trenched contents?

    It has full access to the gearbox, which is supplemented by the variables inscribed in let♪ If that scoop has already this variable, it's redesigned. The scoop of the rehearsal component is not.

    http://plnkr.co/edit/VzT9koNXzAx3B1qvHuJ8?p=preview


    PS: This is a supplemented translation //stackoverflow.com/a/38466789/4928642 from //stackoverflow.com/users/5485167/yurzui ♪


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2