<input type='color' [(ngModel)]='myColor' />
<div class='myElement' [ngStyle]='{backgroundColor: myColor}'>
....
</div>
//...
myColor: string;
//...
<input type='color' #myColor />
<div class='myElement' [ngStyle]='{backgroundColor: myColor.value}'>
<input type="color" [(ng-model)]="backgroundColorStart"><br><br>
<input type="color" [(ng-model)]="backgroundColorEnd"><br><br>
<div
square
[style.background]="backgroundColor"
</div>
export class App {
private _backgroundColorStart:string ="#fefcea"
get backgroundColorStart():string {
return this._backgroundColorStart;
}
set backgroundColorStart(theBar:string) {
this._backgroundColorStart = theBar;
this.backgroundColor="linear-gradient(to bottom right, "+theBar+", " +this.backgroundColorEnd+")"
console.log(this.backgroundColor);
}
private _backgroundColorEnd:string ="#fefcea"
get backgroundColorEnd():string {
return this._backgroundColorEnd;
}
set backgroundColorEnd(theBar:string) {
this._backgroundColorEnd = theBar;
this.backgroundColor="linear-gradient(to top, "+this.backgroundColorStart+", "+this.backgroundColorEnd+")"
console.log(this.backgroundColor);
}
}