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';
}
}
完美。謝謝。 –