<body [ngStyle]="{'background':'blue'}"></body>
I want to set my whole web page of color blue.
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.
[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:
In any component eg 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'
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.