angular - 用户输入文本时以 ng-select 角度隐藏和显示动态占位符
问题描述
我试图在 ng select 控件中显示占位符,但是用户键入了一些东西,占位符并没有隐藏。我用下面的代码克服了这个问题。
@Input() placeholder;
ngOnInit() {
this.searchInput$.pipe(
distinctUntilChanged(),
debounceTime(500)
).subscribe(term => {
term?.length > 0 ? this.placeholder = '' : this.placeholder = this.placeholder;
});
}
html模板:
<ng-select [items]="items$ | async"
[multiple]="multiSelect" bindLabel="name"
[appendTo]="appendTo" [placeholder]="placeholder">
但是当占位符是动态的时,此代码会将占位符重置为空字符串。
任何线索将不胜感激。
解决方案
这是 css 如何实现显示和隐藏占位符
.ng-placeholder {
display: inline-block;
}
.ng-select-focused {
.ng-placeholder {
display: none;
}
}
.ng-has-value {
.ng-placeholder {
display: none;
}
}
推荐阅读
- highcharts - 如何禁用拖动 Highcharts 注释?
- r - 通过 lapply 向数据框列表添加不同的字符
- typescript - 如何在打字稿上传递无序参数?
- android - Gradlew 构建失败,Android Studio 成功
- django - Django 单元测试 - 是否可以为文件上传指定 MIME 类型?
- json - 如何让用户在 Azure ARM 模板中选择 ssh 密码或公钥
- react-native - react-native(expo)中的AuthSession不会返回应用程序Android
- spring - 来自另一个属性的 spring application.yml 参考列表
- c# - PostgreSQL 是否根据使用显式 PK 声明插入的 UPDATE 记录推送自动增量 ID?
- ios - iOS 12 中导航栏的 MFMailComposeViewController 标题颜色未更改