我们可以使用模板添加
X
按钮,然后我们可以在关闭按钮下方添加放大镜图标,请参阅以下工作示例供您参考!
import { Component } from '@angular/core';
@Component({
selector: 'nz-demo-input-allow-clear',
template: `
<nz-input-group [nzSuffix]="inputClearTpl">
<input type="text" nz-input [(ngModel)]="inputValue" placeholder="input with clear icon" />
</nz-input-group>
<ng-template #inputClearTpl>
@if (inputValue) {
<span
nz-icon
class="ant-input-clear-icon"
nzTheme="fill"
nzType="close-circle"
(click)="inputValue = null"
></span>
}
<svg style="margin-left: 5px;" width="20" height="20" class="search-Search-Icon" viewBox="0 0 20 20">
<path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</ng-template>
`,
})
export class NzDemoInputAllowClearComponent {
inputValue: string | null = null;
textValue: string | null = null;
}
Stackblitz Demo