admin管理员组文章数量:1025207
I do not want to use the [clearable]
in ng-select
for leakage of my space. Instead of [clearable]
I want to use only [clearOnBackspace]
but when I write [clearable] = "false"
and [clearOnBackspace] = "true"
it does not work.
enter code here
<ng-select [items]="cities"
bindLabel="name"
placeholder="Select city"
[(ngModel)]="selectedCity"
[clearable]="false"
[clearOnBackspace] = "true"
[excludeGroupsFromDefaultSelection] = "true">
</ng-select>
I do not want to use the [clearable]
in ng-select
for leakage of my space. Instead of [clearable]
I want to use only [clearOnBackspace]
but when I write [clearable] = "false"
and [clearOnBackspace] = "true"
it does not work.
enter code here
<ng-select [items]="cities"
bindLabel="name"
placeholder="Select city"
[(ngModel)]="selectedCity"
[clearable]="false"
[clearOnBackspace] = "true"
[excludeGroupsFromDefaultSelection] = "true">
</ng-select>
Share
Improve this question
edited Jan 28, 2021 at 18:54
Kamil Naja
6,7407 gold badges37 silver badges52 bronze badges
asked Feb 4, 2019 at 5:13
SabbirSabbir
3275 silver badges14 bronze badges
4
- if 'clearable' property is set to false, and clearOnBackspace is set to true, user can remove single item using backspace button. if (this.filterValue || (!multiple && !this.clearable) || !this.clearOnBackspace || !this.hasValue) { template example: <ng-select> (add)=... (remove)=... [multiple]="true" [clearable]="false" [clearOnBackspace]="true" </ng-select> you can hide clear button simply by css – Mebin Joe Commented Feb 4, 2019 at 5:24
-
use
[clearable]="true"
it will be cleared on backspace only – Just code Commented Feb 4, 2019 at 5:36 - The user selects only a single value. So [multiple]="true" not needed. Yap I can remove the cross button using CSS but I want to handle it by JavaScript. – Sabbir Commented Feb 4, 2019 at 5:36
- @Just Code if i make [clearable]="true" it also shows the cross icon. I do not allow it for my space lackage. – Sabbir Commented Feb 4, 2019 at 5:39
1 Answer
Reset to default 3If you do [clearable]="false"
it will disallow to clear the selection.
you can use css to hide the close icon. like this
.ng-clear-wrapper{
display: none;
}
and keep ng-select
as it is
Demo
<ng-select [items]="cities"
bindLabel="name"
placeholder="Select city"
[(ngModel)]="selectedCity"
[clearable]="true"
[clearOnBackspace] = "true"
[excludeGroupsFromDefaultSelection] = "true">
infact you do not need [clearOnBackspace] = "true"
I do not want to use the [clearable]
in ng-select
for leakage of my space. Instead of [clearable]
I want to use only [clearOnBackspace]
but when I write [clearable] = "false"
and [clearOnBackspace] = "true"
it does not work.
enter code here
<ng-select [items]="cities"
bindLabel="name"
placeholder="Select city"
[(ngModel)]="selectedCity"
[clearable]="false"
[clearOnBackspace] = "true"
[excludeGroupsFromDefaultSelection] = "true">
</ng-select>
I do not want to use the [clearable]
in ng-select
for leakage of my space. Instead of [clearable]
I want to use only [clearOnBackspace]
but when I write [clearable] = "false"
and [clearOnBackspace] = "true"
it does not work.
enter code here
<ng-select [items]="cities"
bindLabel="name"
placeholder="Select city"
[(ngModel)]="selectedCity"
[clearable]="false"
[clearOnBackspace] = "true"
[excludeGroupsFromDefaultSelection] = "true">
</ng-select>
Share
Improve this question
edited Jan 28, 2021 at 18:54
Kamil Naja
6,7407 gold badges37 silver badges52 bronze badges
asked Feb 4, 2019 at 5:13
SabbirSabbir
3275 silver badges14 bronze badges
4
- if 'clearable' property is set to false, and clearOnBackspace is set to true, user can remove single item using backspace button. if (this.filterValue || (!multiple && !this.clearable) || !this.clearOnBackspace || !this.hasValue) { template example: <ng-select> (add)=... (remove)=... [multiple]="true" [clearable]="false" [clearOnBackspace]="true" </ng-select> you can hide clear button simply by css – Mebin Joe Commented Feb 4, 2019 at 5:24
-
use
[clearable]="true"
it will be cleared on backspace only – Just code Commented Feb 4, 2019 at 5:36 - The user selects only a single value. So [multiple]="true" not needed. Yap I can remove the cross button using CSS but I want to handle it by JavaScript. – Sabbir Commented Feb 4, 2019 at 5:36
- @Just Code if i make [clearable]="true" it also shows the cross icon. I do not allow it for my space lackage. – Sabbir Commented Feb 4, 2019 at 5:39
1 Answer
Reset to default 3If you do [clearable]="false"
it will disallow to clear the selection.
you can use css to hide the close icon. like this
.ng-clear-wrapper{
display: none;
}
and keep ng-select
as it is
Demo
<ng-select [items]="cities"
bindLabel="name"
placeholder="Select city"
[(ngModel)]="selectedCity"
[clearable]="true"
[clearOnBackspace] = "true"
[excludeGroupsFromDefaultSelection] = "true">
infact you do not need [clearOnBackspace] = "true"
本文标签: javascriptWhat is the alternative of clearable in ngselectStack Overflow
版权声明:本文标题:javascript - What is the alternative of [clearable] in ng-select - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745614537a2159207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论