简体   繁体   中英

how to change send button color when I enter some text in my input tag in angular 6?

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> 
Here i want to change color of send when i enter some text in inputbox

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>

Use NgClass

ex.

[ngClass]="{'color-1': message.length > 0, 'color-2': message.length === 0}"

尝试这个

[style.color]="message.length > 0 ? 'white' : 'red'"  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM