在Angular 2中创建泛型列表迭代器

在Angular 2中创建泛型列表迭代器,angular,Angular,我想包装一个项目列表,但我希望提供唯一模板的灵活性 <list [items]="someItems"> <book-list-item><!-- Books, cars, dogs, whatever --> </book-list-item><!-- This will contain a unique template --> </list> ListItemComponent import {

我想包装一个项目列表,但我希望提供唯一模板的灵活性

<list [items]="someItems">
    <book-list-item><!-- Books, cars, dogs, whatever -->
    </book-list-item><!-- This will contain a unique template -->
</list>

ListItemComponent

import { Component, Input } from '@angular/core';

@Component({
    selector: 'list-item',
    template: `
        <div *ngFor="let item of items">
            <ng-content></ng-content><!-- Whatever book-list-item contains -->
        </div>`
})
export class ListItemComponent {
    @Input() items: Array<any>;
}
import { Component } from '@angular/core';

@Component({
    selector: 'book-list-item',
    template: `
        <div class="row">
            <div class="col-xs-6">Books</div>
            <div class="col-xs-6">Rule</div>
        </div>`

})
export class BookListItemComponent {}
从'@angular/core'导入{Component,Input};
@组成部分({
选择器:“列表项”,
模板:`
`
})
导出类ListItemComponent{
@Input()项:数组;
}
BookListItemComponent

import { Component, Input } from '@angular/core';

@Component({
    selector: 'list-item',
    template: `
        <div *ngFor="let item of items">
            <ng-content></ng-content><!-- Whatever book-list-item contains -->
        </div>`
})
export class ListItemComponent {
    @Input() items: Array<any>;
}
import { Component } from '@angular/core';

@Component({
    selector: 'book-list-item',
    template: `
        <div class="row">
            <div class="col-xs-6">Books</div>
            <div class="col-xs-6">Rule</div>
        </div>`

})
export class BookListItemComponent {}
从'@angular/core'导入{Component};
@组成部分({
选择器:“书籍列表项”,
模板:`
书
统治
`
})
导出类BookListItemComponent{}
显然,我会把书作为物品传递,但这只是一个例子。我可以得到与此类似的工作,但“Books Rule”仅打印在最后一个列表组项中(因为引导)

我真的想了解如何将泛型组件传递给父组件,父组件将作为项目列表中的项目在泛型组件上进行迭代。有人能给我指出正确的方向吗?

看一看。它的功能与您需要的非常相似。您的主要挑战是绑定这些值。你也可以看看。它与RC1有关,甚至他在评论中也提到setLocal不再存在,您需要传递上下文