问题描述
在打开 ngx-bootstrap-modal 加载 ngx-image-cropper 时注意一些间歇性加载失败。做了一些尝试和错误,我注意到只要在 loadImageFailed() 触发之前打开模态。裁剪器将加载,一切似乎都正常。和不渲染到 DOM 有关系吗?
我找不到原因,还是我遗漏了什么?
希望对此有所了解。
提前致谢。
这是模态的样子:
<!-- EDIT MODAL -->
<article bsModal #lgModal="bs-modal" class="modal fade" tabindex="-1" role="dialog"
aria-labelledby="dialog-sizes-name1">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<form (ngSubmit)="instructorService.updateCover(instructor.id)">
<section class="modal-header">
<h4 id="dialog-sizes-name1" class="modal-title pull-left">EDIT BANNER</h4>
<button type="button" class="close pull-right" (click)="lgModal.hide()" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</section>
<section class="modal-body">
<cropper></cropper>
</section>
<section class="modal-footer d-flex bd-highlight">
<div class="mr-auto p-2 bd-highlight">
<input class="overflow-x" type="file" (change)="onSelectFile($event)" hidden #browser>
<button type="button" class="btn btn-pri" (click)="browser.click()"><b>broWSE</b></button>
</div>
<div class="p-2 bd-highlight">
<button type="button" class="btn btn-sec btn-block"
(click)="lgModal.hide()"><b>CANCEL</b></button>
</div>
<div class="p-2 bd-highlight">
<button type="submit" class="btn btn-dark btn-block px-4"
(click)="lgModal.hide()"><b>SAVE</b></button>
</div>
</section>
</form>
</div>
</div>
</article>
解决方法
通过将其连接到延迟加载组件方法来设法解决它。但我认为这可能只是一种解决方法。但是,嘿,在等待别人发光的同时,这可能对你们中的任何人有所帮助。
关于如何延迟加载组件。我发现了 Netanel Basal 的这篇很棒的文章。
https://netbasal.com/welcome-to-the-ivy-league-lazy-loading-components-in-angular-v9-e76f0ee2854a
干杯~