javascript - How to pass multiple data back from child to parent component in angular? -
currently, using angular 4 school project. have array, each item child component can updated , deleted, means should know index , data.
parent.ts:
updone(i:number,stc:string):void{ this.myarray[i]=stc } delete(edu:string):void{ this.myarray=this.myarray.filter(x=>x!==edu) } parent.html:
<child-com [edu]=x [num]=i (updstr)="updone($event)" (delstr)="delete($event)"></child-com> child-com.ts:
@input() edu:string @input() num:number @output() updstr: eventemitter<string> = new eventemitter<string>() @output() delstr: eventemitter<string> = new eventemitter<string>() //some other code here save():void{ this.updstr.emit(this.edu) this.updating=false } del():void{ this.delstr.emit(this.edu) } delete works well, without doubt. problem updating. actually, using *ngfor, trackby, , printing manually, problem can solved. wanna try using child component, in react. when play around react, can use javascript closure, i.e. myfunc.bind(this,i,stc).
i've tried using bind here, no results
code when using bind:
parent.ts:
@output() updstr: eventemitter<number,string> = new eventemitter<number,string>() parent.html:
//i've tried order //this,i,$event //$event,this,i <child-com [edu]=x (updstr)="updone.bind(this,$event,i)" (delstr)="delete($event)"></child-com> and generics in typescript doesn't allow multiple data, cant emit more 1 data
so question is, how can pass data @ once child parent, using emit or bind?
thanks alex, using object can substitute multiple data passing. make sure data correct, interface used, kind of this
export interface interview{ num:number payload:{ dt:string seeker:string } } and used like
@output() updstr: eventemitter<interview> = new eventemitter<interview>()
Comments
Post a Comment