2016-12-26 145 views
3

如何设置div的高度等于窗口的高度?我已经在这个问题上Dynamically updating css in Angular 2我必须用下面的代码中发现:设置div的高度等于窗口的高度angular2

<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. 我如何设置div的高度等于Angular 2和TypeScript的内窗高度?
  2. 我怎么能一次做到这一点,因为我必须这样做多个thimes?

回答

8

这不起作用,因为angular2试图搜索this.window.innerHeight

更新您的组件,

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

    myInnerHeight: window.innerHeight; 
    constructor(){} 

} 

,并使用它像这样:

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

我试图用'[style.height]',有没有一些文档,我可以指得到知道这些属性? –

+0

@GiridharKarnik https://angular.io/docs/ts/latest/guide/template-syntax.html#!#style-binding – echonax