简体   繁体   English

Angular 2 RC1多个组件一个表

[英]Angular 2 RC1 Multiple components one table

Overview: I am developing a Todo list using Angular 2 and an API I developed earlier. 概述:我正在使用Angular 2和我先前开发的API开发Todo列表。 Currently, the functionality of the front and back end is completed. 当前,前端和后端的功能已完成。 My new goal is to link the components of the todo list together, under one HTML table. 我的新目标是在一个HTML表下将待办事项列表的组件链接在一起。 The todo list is in one component html file (tasklist.component.html) and a sorting component in another (sort.component.html). 待办事项列表位于一个组件html文件(tasklist.component.html)中,而排序组件位于另一个html文件(sort.component.html)中。 These two components are held under the parent component (todo.component.html). 这两个组件位于父组件(todo.component.html)下。

Parent Component (todo.component.html): 父组件(todo.component.html):

<h1>
  {{title}}
</h1>

<app-addtask> </app-addtask>
<app-search> </app-search>

<table border="1" style="width:100%">

  <app-sort> </app-sort> <!-- Headers -->

  <app-tasklist> </app-tasklist> <!-- Content -->

</table>

tasklist component: 任务列表组件:

<td (click)=completeTask(item) style="width:75px;">
    <input type="checkbox" name="complete" *ngIf="!item.IsComplete" >
    <input type="checkbox" name="complete" *ngIf="item.IsComplete" checked="checked">
</td>

<td (click)=completeTask(item)> 
    <p *ngIf="item.IsComplete" style="text-decoration: line-through;">  {{item.Name}}  </p>
    <p *ngIf="!item.IsComplete" >  {{item.Name}}  </p>
</td>
<td style="width:250px;"(click)=completeTask(item) > 
    <p *ngIf="item.IsComplete" style="text-decoration: line-through;">  {{item.DueDate}}  </p>
    <p *ngIf="!item.IsComplete" >  {{item.DueDate}}  </p>
</td>

<!--<app-deletetask></app-deletetask>-->

<td style="width:115px;">
    <button type="button" (click)="deleteTask(item, $event)">Delete</button> 
</td>

sort component: 排序组件:

  <td style="width:75px;" (click)="Sort('iscomplete')"><a>Complete</a></td>
  <td (click)="Sort('name')"><a>Name</a></td>
  <td style="width:250px;" (click)="Sort()"><a>Due Date</a></td>
  <td style="width:115px;">Option</td>

If I combine all of the components together I can get the data to display correctly. 如果将所有组件组合在一起,则可以正确显示数据。 However, with the way it is now, a tbody tag is being generated which throws off the columns. 但是,按照现在的方式,正在生成一个tbody标签,该标签抛出列。 Ignore the ugly formatting. 忽略丑陋的格式。

web page currently with dev tools 当前带有开发工具的网页

How do I have separate components and utilize them correctly with respect to vies. 我如何拥有单独的组件,以及如何相对于竞争对手正确使用它们。

Please take a look at this answer . 请看看这个答案

Basically if you want a structure of a table try to put appropriate components with attribute selector rather than custom tag. 基本上,如果您想要表的结构,请尝试使用属性选择器而不是自定义标记放置适当的组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM