设置div的高度等于窗口角度的高度

时间:2016-12-26 17:15:17

标签: angular typescript

如何设置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>

但是这给了我下一个错误:

  

无法读取未定义

的属性innerHeight

我现在的问题是:

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

1 个答案:

答案 0 :(得分:14)

它无效,因为angular2正在尝试搜索this.window.innerHeight

更新您的组件,

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

    myInnerHeight: window.innerHeight;
    constructor(){}

}

并像这样使用它:

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