使用Angular 2编辑单击功能

时间:2016-11-23 09:45:20

标签: html angular typescript

每当我点击编辑按钮时,我想编辑特定行的标题和正文,这样每当我点击编辑它时,我应该将我的标签变成输入标签。我尝试使用 ngif ,但它会使所有行都像这样编辑。任何人都可以帮助我做错了什么?

type_mat4x4.inl

打字稿代码:

B3+7

1 个答案:

答案 0 :(得分:0)

export class TasksComponent implements OnInit {

  displayRow:number = 0;

  Temp(idx) {
    this.displayRow = idx;
  }
<tr *ngFor = "let task of tasklist.task let idx=index">


    <td>{{task.id}}</td>
    <td *ngIf="displayRow != idx">{{task.title}}</td> 
    <td *ngIf="displayRow != idx">{{task.author}}</td>


    <td *ngIf="displayRow == idx"> <input placeholder = 'Username'></td>
    <td *ngIf="Display == idx"> <input placeholder = 'Title'></td>


    <td>
    <a class="btn btn-Danger" (click) = Temp(idx) > Edit </a> 
    <a class="btn btn-Danger" (click) = Delete(task) > Delete </a>
     </td>

  </tr>

  <tr>

  <td><input placeholder = 'ID' [(ngModel)] = 'newTaskid'  ></td>
  <td><input placeholder = 'Username' [(ngModel)] = 'newTasktitle' ></td>
  <td><input placeholder = 'Title' [(ngModel)] = 'newTaskauthor' ></td>
  <td> <Button class="btn btn-link" (click) = Edit(newTaskid,newTasktitle,newTaskauthor)> Save </Button> </td>

  </tr>

 </table>

</div>