gpt4 book ai didi

angular - 将 div 的高度设置为等于窗口 Angular 高度

转载 作者:太空狗 更新时间:2023-10-29 17:22:33 34 4
gpt4 key购买 nike

如何将 div 的高度设置为等于窗口的高度?我在这个问题上找到了Dynamically updating css in Angular 2说我必须使用下面的代码:

<div class="home-component" 
[style.width.px]="width"
[style.height.px]="height">Some stuff in this div</div>

我已经像下面的代码一样更新了这段代码:

<div class="imagecontainer" [style.height.px]="window.innerHeight">
Some code
</div>

但这给了我下一个错误:

Cannot read property innerHeight of undefined

我现在的问题是:

  1. 如何使用 Angular 和 TypeScript 将 div 的高度设置为等于内部窗口的高度?
  2. 我怎么能一次性完成这个,因为我必须多次这样做?

最佳答案

它不起作用,因为 angular2 正在尝试搜索 this.window.innerHeight

更新你的组件,

@Component({...})
export class MyClass {

myInnerHeight: window.innerHeight;
constructor(){}

}

并像这样使用它:

<div class="imagecontainer" [style.height.px]="myInnerHeight">
Some code
</div>

关于angular - 将 div 的高度设置为等于窗口 Angular 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41334265/

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