我试图调用这个自动检测功能从我的组件.ts文件到我的.scss文件,我不知道如何或如果它甚至是可能的。example.component.scss
.content {
display: flex;
align-items: center;
text-align: center;
height: getScreenHeight; <--- ERROR
width: getScreenWidth; <--- ERROR
}
example.component.ts
import { Component, OnInit, HostListener } from '@angular/core';
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
styleUrls: ['./example.component.scss']
})
export class exampleComponent implements OnInit {
public getScreenWidth: any;
public getScreenHeight: any;
constructor() { }
ngOnInit(): void {
this.getScreenWidth = window.innerWidth;
this.getScreenHeight = window.innerHeight;
}
@HostListener('window:resize', ['$event'])
onWindowResize() {
this.getScreenWidth = window.innerWidth;
this.getScreenHeight = window.innerHeight;
}
}
作为参考,我使用此功能detection
尝试在html和. scss中调用。没有任何效果,也没有发现类似的问题
1条答案
按热度按时间8i9zcol21#
CSS不是动态的,所以从SCSS文件中处理它会给你带来问题,而不是使用内联样式来解决这些问题。