Search code examples
angulartypescriptdata-binding

How can i display image from component to another using click on it?


i have a div which is contain an image and i need to view it in another div which is in another component (in angular ) i'm starting with this code:

Update:

image: ImageData;
@Output() sendimage = new EventEmitter<ImageData>();

https://i.sstatic.net/CAhKQ.png


Solution

  • You try this

    Child component e.g. app-child

    @Output() sendImage: EventEmitter<ImageData>;
    constructor() {
            this.sendImage= new EventEmitter<ImageData>();
    }
    send() {
      this.sendImage.emit(this.image);
    }
    

    Parent component Template

    <app-child
     (sendImage) = "receiveIamge($event)"
    ></app-child>
    

    And its controller:

    receiveImage(image: ImageData) {
         // your process here
    }