简体   繁体   English

ngStyle 设置整个网页的背景颜色

[英]ngStyle to set background color of whole web page

<body [ngStyle]="{'background':'blue'}"></body> I want to set my whole web page of color blue. <body [ngStyle]="{'background':'blue'}"></body>我想将整个网页设置为蓝色。

I tried using height=100% and width=100% like this <body [ngStyle]="{'background':getColor(),'height':'100%','width':'100%'}"></body> , but still whole web page is blank.我试过像这样使用 height=100% 和 width=100% <body [ngStyle]="{'background':getColor(),'height':'100%','width':'100%'}"></body> ,但整个网页仍然是空白的。

[ngStyle] onyl works on the element it is specified in. To programmatically change the style of the applications <body></body> - since it is not part o any component - you can do the following: [ngStyle] onyl 在指定的元素上工作。要以编程方式更改应用程序<body></body>的样式 - 因为它不是任何组件的一部分 - 您可以执行以下操作:

In any component eg app.component.ts在任何组件中,例如 app.component.ts

import { Component, Inject } from '@angular/core';
import { DOCUMENT } from "@angular/common";

export class AppComponent {

    constructor(
        @Inject(DOCUMENT) document: Document
    ) {
        document.body.style.background = 'blue'
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM