Can you try using like this?
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[image-fit]',
host: {
'(click)':"_fit()"
}
})
export class ImageFitDirective {
constructor(
private _elementRef: ElementRef
) { }
ngAfterViewInit(): void {
this._fit()
}
_fit(): void {
const width = this._elementRef.nativeElement.offsetWidth;
const height = this._elementRef.nativeElement.offsetHeight;
console.log('width', width)
console.log('height', height)
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…