angular2不能渲染为组件

时间:2017-10-24 09:33:07

标签: angular

我试图将表格行作为一个组件呈现:

<table class="table table-responsive">
    <thead>
        <tr>
            <th>ID</th>
            <th>Imię</th>
            <th>Nazwisko</th>
            <th>Data od</th>
            <th>Data do</th>
            <th>Pokój</th>
            <th>Typ pokoju</th>
            <th>Cena</th>
        </tr>
    </thead>
    <tbody>
        <app-rezerwacja-item
            *ngFor="let rezerwacjaEl of rezerwacje; let i = index"
            [rezerwacja]="rezerwacjaEl"
            [index]="i">
        </app-rezerwacja-item>
    </tbody>
</table>

rezerwacja-item-component

但是浏览器首先呈现app-rezerwacja-item,然后呈现一行,而表格不能显示&#34;&#34;&#34;行作为行。他们离开了网格。桌子也崩溃了。

有人能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

您可以设置&#39; app-rezerwacja-item&#39;作为选择器的一部分。我没有你的代码,所以改编了这个例子:

父HTML

  <table>
      <tbody>
      <tr app-rezerwacja-item *ngFor="let rezerwacjaEl of rezerwacje; let i = index"
            [rezerwacja]="rezerwacjaEl"
            [index]="i">
      </tr>
      </tbody>
  </table>

子组件类:

 @Component({
  selector: 'tr [app-rezerwacja-item]',
  template: `
    <td>{{rezerwacja.name}}</td>
  `
})

DEMO