将div的高度设置为等于窗口角度的高度 [英] Set height of div equal to height of window angular

查看:55
本文介绍了将div的高度设置为等于窗口角度的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置 div 的高度等于窗口的高度?我在这个问题上发现在Angular 2中动态更新CSS 表示我必须使用以下代码:

How could I set the height of a div equal to the height of the window? I've found on this question Dynamically updating css in Angular 2 saying that I must use code below:

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

我已经更新了以下代码,例如以下代码:

I've update this code like code below:

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

但这给我下一个错误:

无法读取未定义的属性 innerHeight

我的问题现在是:

  1. 如何使用Angular和TypeScript将 div 的高度设置为等于内部窗口的高度?
  2. 由于必须多次执行,我一次只能执行一次该操作吗?
  1. How could I set the height of the div equal to the height of the inner window with Angular and TypeScript?
  2. How could I do this in one time, because I've to do this multiple times?

推荐答案

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

It's not working because angular2 is trying to search for this.window.innerHeight.

更新您的组件

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

    myInnerHeight: window.innerHeight;
    constructor(){}

}

并像这样使用它:

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

这篇关于将div的高度设置为等于窗口角度的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆