[英]Angular mat input mat icon hide show
我的代码我有一个带有垫子图标的输入,允许清除每次存在值时显示图标的字段。
我想要做的是当有一个值时不显示图标,而只有当我将鼠标悬停在它上面时。
提前致谢。
html
<mat-form-field appearance="fill">
<mat-label>Clearable input</mat-label>
<input matInput type="text" [formControlName]="controller">
<mat-icon matSuffix *ngIf="controller.value" class="iconDisplay" (click)="clearInput()">highlight_off</mat-icon>
</mat-form-field>
ts
export class testComponent {
@Input() public controller: AbstractControl;
clearInput() {
this.controller.setValue(null)
}
}
scss
.iconDisplay {
visibility: hidden
}
input:hover > .iconDisplay {
visibility: visible
}
你使用类似的东西:
<input ... [ngClass.iconDisplay]="showIcon" (mouseover)="showIcon=true" (mouseout)="showIcon=false"
我有一个类似的用例,我是这样做的:
HTML:
<div class="clearableInput">
<mat-form-field appearance="fill">
<mat-label>Clearable input</mat-label>
<input matInput type="text" [formControlName]="controller">
<div class="iconDisplay">
<mat-icon matSuffix *ngIf="controller.value" class="iconDisplay" (click)="clearInput()">highlight_off</mat-icon>
</div>
</mat-form-field>
</div>
CSS:
.clearableInput{
&:hover {
.iconDisplay {
display: block !important;
}
}
}
.iconDisplay {
display: none;
}
希望这可以帮助! :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.