I'm using my-component
in the angular material custom CdkStepper.
The custom CdkStepper works and renders the my component.
But it looks like impossible to get the height and width of my-component
when I use it in the custom CdkStepper. If the component is used outside the stepper, the height and width will be not 0.
import { AfterViewInit, Component, ElementRef } from '@angular/core';
@Component({
selector: 'my-component',
templateUrl: './image-editor.component.html',
styleUrls: ['./image-editor.component.scss'],
host: { 'class': 'd-block' }
})
export class MyComponent implements AfterViewInit {
constructor(private el: ElementRef) { }
public ngAfterViewInit(): void {
console.log(`offsetWidth : ${(this.el.nativeElement as HTMLElement).offsetWidth}`); // offsetWidth : 0
}
}
<lib-stepper linear (selectionChange)="selectionChangeData=$event">
<cdk-step>
<ng-container *ngIf="selectionChangeData?.selectedIndex === 0 || selectionChangeData?.selectedIndex == null ">
<!-- works and will be displayed, but 'offsetWidth' is always 0 -->
<my-component></my-component>
</ng-container>
</cdk-step>
...
</lib-stepper>
Anyone know why the height and width is always 0?