我有一个模式,在其中我会使用一个组件(ngx- image-cropper ),但每次在image-cropper上“无法读取未定义的属性实例”时,我都会得到这个错误。
Preview()调用成功,this.logoToUpload工作正常,问题是使用图像裁剪器组件打开模式,否则模式也工作正常。
下面是我的代码:
import { ImageCroppedEvent, LoadedImage } from 'ngx-image-cropper';
@Component({
selector: 'logo',
templateUrl: './logo.component.html',
styleUrls: ['./logo.component.scss']
})
export class LogoComponent implements OnInit {
constructor(
private modalService: NgbModal,
) {}
ngOnInit() {}
preview(content) {
var mimeType = this.logoToUpload.type;
if (mimeType.match(/image\/*/) == null) {
return;
}
debugger;
// Show preview
this.modalService.open(content).result.then(
(result) => {
//DO SOMETHING IN CASE RESULT IS SAVE OR NOT
}, (reason) => {
});
}HTML:
<ng-template #modalCroppingImage let-modal>
<div class="modal-header modal-header-new">
Select area
</div>
<div class="modal-body">
<image-cropper [imageFile]="logoToUpload"
[maintainAspectRatio]="true"
[aspectRatio]="4 / 3"
format="png"
(imageCropped)="imageCropped($event)"
(imageLoaded)="imageLoaded()"
(cropperReady)="cropperReady()"
(loadImageFailed)="loadImageFailed()"></image-cropper>
</div>
<div>
<button type="button" class="btn btn-primary button-modal-detail-new" (click)="modal.close('Save'); resetView();">SAVE<!--Close--></button>
<button type="button" class="btn btn-primary button-modal-detail-new" (click)="modal.close('Close'); resetView();">CLOSE<!--Close--></button>
</div>
</ng-template>编辑:我也得到了这个错误:
StaticInjectorError(AppModule)ImageCropperComponent -> CropService: StaticInjectorError(Platform: core)ImageCropperComponent -> CropService: NullInjectorError:不提供CropService!
发布于 2021-09-03 15:49:00
我发现了这个问题,Angular 8不再支持ngx-image-cropper。如果你有同样的问题,你必须安装3.3.5版本。
https://stackoverflow.com/questions/69045150
复制相似问题