我试图根据窗口的大小更改布尔值,但在语法上遇到了问题。
下面是我得到的信息:
export class AppComponent {
isSmall = true;
constructor(){
let windowWidth = window.innerWidth;
if (windowWidth <= 700) {
isSmall = true;
}
else {
isSmall = false;
}
}
}
任何帮助都将不胜感激!
发布于 2017-02-14 11:24:23
export class AppComponent {
isSmall:boolean = true;
windowWidth: number;
constructor(){
this.windowWidth = window.innerWidth;
if (windowWidth <= 700) {
this.isSmall = true;
}
else {
this.isSmall = false;
}
}
}
发布于 2017-02-14 11:18:32
如果你想获取窗口宽度在角度下面的代码将会有所帮助..
angular.element($window).bind('resize', function () {
alert($window.innerWidth);
});
现在可以使用$window.innerWidth设置您的变量
发布于 2017-02-14 14:55:01
要在调整窗口大小时更新该值,可以使用
@HostListener('window:resize')
onResize() {
this.isSmall = windowWidth <= 700;
}
https://stackoverflow.com/questions/42217189
复制相似问题