gpt4 book ai didi

javascript - 在 Angular 2 中使用 if/else 语句更改 boolean 值

转载 作者:行者123 更新时间:2023-11-30 15:31:16 25 4
gpt4 key购买 nike

我试图根据窗口的大小更改 boolean 值,但语法有问题。

这是我得到的:

    export class AppComponent {

isSmall = true;

constructor(){
let windowWidth = window.innerWidth;

if (windowWidth <= 700) {
isSmall = true;
}
else {
isSmall = false;
}
}
}

任何帮助将不胜感激!

最佳答案

export class AppComponent {

isSmall:boolean = true;
windowWidth: number;

constructor(){
this.windowWidth = window.innerWidth;

if (windowWidth <= 700) {
this.isSmall = true;
}
else {
this.isSmall = false;
}
}
}

关于javascript - 在 Angular 2 中使用 if/else 语句更改 boolean 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42217189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com