如何将图像从孩子发送到父母

时间:2019-07-09 18:10:35

标签: typescript angular7

在子组件形式中,我将图像作为输入并希望将该图像传递给父组件,并将该图像显示给父组件

1 个答案:

答案 0 :(得分:0)

子控件-子component.ts

@Component({
 selector: 'child-comp',
})
export class childComponent
{

 @Output() OnImageUpload: EventEmitter<any> = new EventEmitter<any>();

 constructor(){}

 uploadImage(){
   let imgObject:any[]=[];
   //--put all your image objects inside imgObject in the form of array
   this.OnImageUpload.emit(imgObject);
  }
}

---------------------父组件.html

<div>
   <child-comp (OnImageUpload)='processImage($event)'> </child-comp>
</div>

--------------------------- parent.component.ts

   export class parentComponent{

     processImage(imgObject:any){
     //--play with your imgObject on parent component here
     }
   }