简体   繁体   English

Angular 5 ng-select

[英]Angular 5 ng-select

I am using ng-select component from https://github.com/ng-select/ng-select .我正在使用https://github.com/ng-select/ng-select 中的ng-select 组件。 However the content of the dropdown is in some cases too long.然而,下拉菜单的内容在某些情况下太长了。 The string in the dropdown will be shortened with ... Is it possible to make the dropdown bigger than the input width, according to the length of the content?下拉列表中的字符串将被缩短...是否可以根据内容的长度使下拉列表大于输入宽度? Possibly with CSS styling (custom).可能使用 CSS 样式(自定义)。

<div layout="row">
    <label>Your first ng-select</label>
    <ng-select class="custom" [items]="cities"
               bindLabel="name"
               placeholder="Select city"
               [(ngModel)]="selectedCity">
    </ng-select>

    <label>Your first ng-select</label>
    <ng-select class="custom" [items]="cities"
               bindLabel="name"
               placeholder="Select city"
               [(ngModel)]="selectedCity">
    </ng-select>
</div

In the CSS/SCSS (what you are using for styling) set在 CSS/SCSS(你用于样式的东西)集合中

.ng-dropdown-panel {
    min-width: 100%;
}

However it doesn't look that good...不过好像不太好...

在此处输入图片说明

Alternative:选择:

Remove white-space: nowrap;删除white-space: nowrap; from .ng-dropdown-panel .ng-dropdown-panel-items .ng-option then it breaks into multiple lines..ng-dropdown-panel .ng-dropdown-panel-items .ng-option然后它分成多行。

在此处输入图片说明

  1. Add encapsulation: ViewEncapsulation.None.添加封装:ViewEncapsulation.None。
  2. Give it a class name.给它一个类名。 And override the CSS using it并使用它覆盖 CSS

 .ng-select.custom .ng-value-container { height: 10px; }

Here ng-select is the component and custom is the class name.这里 ng-select 是组件,custom 是类名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM