I can't get the real width or height after image loaded. Does anyone know how to do it in the correct way?
HTML:
<div class="editor-container">
<img src="{{photoUrl}}" alt="" />
</div>
CSS:
.editor-container {
position: relative;
width: 100%;
}
.editor-container img {
display: block;
width: 100%;
height: auto;
}
TypeScript:
ngAfterViewInit(){
try {
console.log( document.getElementsByClassName('editor-container') );
console.log( document.getElementsByClassName('editor-container')[0] );
console.log( 'clientWidth', document.getElementsByClassName('editor-container')[0].clientWidth );
console.log( 'scrollWidth', document.getElementsByClassName('editor-container')[0].scrollWidth );
} catch (err) {
console.error(err);
}
}
result:
.scrollWidthinto a variable, and then<img src="" width="{{maxWidth}}" />Thanks