Reputation: 343
how to change send button colour when I enter some text in my input tag in angular 6? In the image I have to change colour of send button when my text is entered in input text field
<div class="conversation">
<input id="chatMessageBox" row="1" placeholder="continue typing.." autocomplete="off" autocorrect="off"
autocapitalize="off" spellcheck="false" class="text-input" [(ngModel)]="message" (keydown)="sendMessageUsingKeypress($event)">
<div class="send">
<i class="material-icons" (click)="onSubmit(message)">
send
</i>
<br>
</div>
</div>
Upvotes: 1
Views: 805
Reputation: 1115
Simple way use angular style [style.background-color]="message && message != '' ? 'red' : 'green'" [style.color]="message && message != '' ? 'black' : 'white'"
<div class="send" [style.background-color]="message && message != '' ? 'red' : 'green'" [style.color]="message && message != '' ? 'black' : 'white'">
<i class="material-icons" (click)="onSubmit(message)">
send
</i>
<br>
</div>
Upvotes: 2
Reputation: 1000
Use NgClass
ex.
[ngClass]="{'color-1': message.length > 0, 'color-2': message.length === 0}"
Upvotes: 1