【问题标题】:set icon after input onChange输入onChange后设置图标
【发布时间】:2021-07-23 14:25:25
【问题描述】:

我想在输入字段后添加图标,它将在更改时显示。 和另一个图标(如果它不在焦点上)。

谁能帮帮我 我已经尝试过类似下面的方法,但我不知道如何在其中切换图标。

<input matInput type="text" style="width: 200px;">
<button mat-mini-fab  style="float: right;" color="primary" (click)="element.disabled = !element.disabled">
  <mat-icon>{{element.disabled ? 'home' : 'edit'}}</mat-icon>
</button>

谢谢

【问题讨论】:

标签: angular icons mat-input


【解决方案1】:

我找到了办法。

在 .ts 文件中定义两个布尔变量。并更改输入元素的焦点和焦点事件的值。

home: boolean = false;
edit:boolean = true;

onFocusOutEvent(event: any){
// toggle as you want to use it.
}
onFocusEvent(){
// toggle as you want to use it.
}

在 HTML 文件中

<input matInput type="text" [formControlName]="element.id" (focusout)="onFocusOutEvent($event)" (focus)="onFocusEvent($event)" >

<button style="float: right;" color="primary" *ngIf="edit">
     <mat-icon>edit</mat-icon>
</button>
<button *ngIf="home" style="float:left;">
<mat-icon>home</mat-icon>
</button>

我希望它对某人有所帮助。谢谢

【讨论】:

    猜你喜欢
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 2018-06-13
    • 2019-05-07
    • 1970-01-01
    • 2018-09-18
    • 2019-07-26
    相关资源
    最近更新 更多