我正在构建联系人列表应用程序,用户可以使用输入字段添加联系人,就像我们通常用于获取数据一样,我已完成添加和删除联系人,但我对如何通过单击旁边的按钮编辑添加的联系人感到困惑添加的联系人,情况是我点击编辑按钮,联系人将在输入字段中,我将编辑联系人并点击更新按钮,编辑后的联系人将回到联系人列表中,我可能会得到-ve 投票,但我真的很想看看它是如何发生的,比如在输入字段中联系以进行编辑。
这是我为它写的以 id 作为参数
updateparent(value){
for(var i = 0; i < this.array.length ; i++){
console.log('inside for');
if(value == this.array[i].idobj){
break;
}
}
如果之后呢?:)
父母的HTML:
<h1 class= "text-center">ToDo App</h1>
<div class = "form-group">
<lable>Task</lable>
<input name = "tasks" #task class = "form-control" >
<lable>Detail</lable>
<input type = "text" name = "taskdetail" #detail class = "form-control" >
<button type = "submit" class = "btn btn-default"
(click) = "addtask(task, detail)">Add Task</button>
<child-component *ngFor = "#todo of array"
[taskobject] = "todo" (childevent) = "deleteparent($event)">
Loading... </child-component>
</div>
子组件的 HTML 以显示从父组件捕获的数据:
{{taskobject.taskobj}}
{{taskobject.detailobj}}
{{taskobject.idobj}}
<button type = "button" class = "btn btn-default"
(click) = "deletetask(taskobject.idobj)">Delete</button>
<button type = "button" class = "btn btn-defualt"
(click) = "updatetask(taskobject.idobj)">Update</button>
`