cstefanache / angular2-img-cropper

Angular 2 Image Cropper
MIT License
364 stars 135 forks source link

`setImage` as an input #106

Open altschuler opened 7 years ago

altschuler commented 7 years ago

It would be very useful to be able to set the image data through an input. Current I'm wrapping the cropper in another component that takes the image data as input and calls setImage on the cropper during ngAfterViewInit:

import { Component, Input, ViewChild, AfterViewInit, ChangeDetectionStrategy } from '@angular/core';
import { ImageCropperComponent as Ng2ImageCropperComponent, CropperSettings } from 'ng2-img-cropper';

@Component({
    selector: 'pt-image-cropper',
    template: '<img-cropper #cropper [image]="data" [settings]="settings"></img-cropper>',
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ImageCropperComponent implements AfterViewInit {

    @Input() settings: CropperSettings;
    @Input() data: any;
    @Input() image: HTMLImageElement;

    @ViewChild('cropper', Ng2ImageCropperComponent)
    cropper: Ng2ImageCropperComponent;

    constructor() { }

    ngAfterViewInit() {
        this.cropper.setImage(this.image);
    }
}

Thank you very much for this great project!

cstefanache commented 7 years ago

Do you need this released quickly? I am quite tight with the schedule to do the change but if you can do a pull request I will be glad to integrate, test and release it ASAP.

thanks for contributing!

altschuler commented 7 years ago

No, it's no hurry, the solution above works for now. I've got a really tight schedule myself as well, so I will have no time to do a PR right at this moment, but will be happy to work it out later on :)