2017-10-10 269 views
0

我想改變文本框的背景顏色,當有人在角度4中的文本框中輸入顏色時。但它不工作。我正在使用Visual Studio代碼。這裏是我的代碼:更改文本框的背景顏色

<input type="text" ngModel="myColor" ng-style="{background-color: myColor}"> 
+0

[ngStyle] = 「{背景色:myColor}」 是角(2+)方法 –

回答

-1

試試這個:

<input type="text" [(ngModel)]="myColor" [ngStyle]="{'background-color': myColor}"> 
-1

角語法應爲[(ngModel)]和[ngStyle]

<input type="text" [(ngModel)]="myColor" [ngStyle]="{'background-color': myColor}"> 

DEMO

+0

爲什麼downvote這裏? – Sajeetharan

0

這是不正確的語法使用ngClass,嘗試以下代碼:

<input type="text" ngModel="myColor" [ngStyle]="{'background-color': myColor}">