You can create a directive, that adapts to the resize of the screen, but honestly, this should be done simply using media queries
:
mat-spinner {
width: 300px !important;
height: 300px !important;
}
@media screen and (max-width: 768px) {
mat-spinner {
width: 150px !important;
height: 150px !important;
}
}
@media screen and (max-width: 480px) {
mat-spinner {
width: 50px !important;
height: 50px !important;
}
}
Instead of complicated angular code.
@Directive({
selector: '[dynamicWidth]',
})
export class DynamicWidthDirective {
cdr = inject(ChangeDetectorRef);
spinner = inject(MatProgressSpinner);
percentage = model(1, {
alias: 'dynamicWidth',
});
@HostListener('window:resize', ['$event'])
onResize(event: any) {
this.spinner!.diameter = event.target.innerWidth * this.percentage();
this.cdr.detectChanges();
}
ngAfterViewInit() {
this.spinner!.diameter = window.innerWidth * this.percentage();
this.cdr.detectChanges();
}
}