javascript - Angular2: How to edit a field -
i'm building contact list app user can add contact using input field getting data, i'm done adding , delete contact i'm confused how edit added contact clicking button next added contact, situation click on edit button , contact in input field edit contact , click on update button , edited contact there in list of contact, may -ve voting want see how happen contact in input field edit.
here wrote taking id argument
updateparent(value){ for(var = 0; < this.array.length ; i++){ console.log('inside for'); if(value == this.array[i].idobj){ break; } }
what next after if? :)
html of parent:
<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 of child component display data catched parent :
{{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> `
if contact number
1 value in array match existing value contact , when got value of index( or i) match splice
value array , update new value in array using push method. this:
updateparent(value){ for(var = 0; < this.array.length ; i++){ console.log('inside for'); if(value == this.array[i].idobj){ this.array.splice(i,1); var newcontact = value this.array.push(value); break; } }
hope ! if not provide plnkr code make correct !
Comments
Post a Comment