1
如何更改背景颜色以十六进制动态角度?如何在Angular2中动态改变背景颜色?
转换十进制值十六进制值的角度来改变背景颜色动态
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<h1>Change Background Color Dynamically</h1>
<!-- Chang Background Color By Increasing Or Decreasing Color Value -->
<button (click)="bgColor = bgColor + 15">+</button>
<button (click)="bgColor = bgColor - 15">-</button>
<div [ngStyle]="{'background-color': '#' + bgColor}">
Changable Background Color
</div>
`
})
export class AppComponent {
bgColor;
constructor() {
this.bgColor = 'BBFFFF';
}
}
完美。谢谢。 –