ng-bootstrap - Typeahead dropdown width

核能气质少年 提交于 2019-12-01 19:28:48

Add encapsulation: ViewEncapsulation.None to the component

import {Component, ViewEncapsulation} from '@angular/core';

@Component({
  selector: 'ngbd-typeahead-template',
  templateUrl: 'src/typeahead-template.html',
  styleUrls: ['src/typeahead-template.css'],
  encapsulation: ViewEncapsulation.None
})

See updated plunker

Without ViewEncapsulation.None, the styles applied in this component will only effect this component and not any other component on this page.

Read this for more information

For me works ng-deep. Looks more safe and scoped:

::ng-deep .dropdown-menu { width: 100%; }

@Nandita's answer is correct, directly apply a width to dropdown menu won't affect.

And you want the dropdown menu to have same width as input, so you should add below CSS to her answer:

.dropdown-menu { width: 300px;}

Check result: https://next.plnkr.co/edit/YvOymCLAwYgU3VmJ

This code 100% work, but with the class .dropdown-menu any other dropdown will be changed

::ng-deep .dropdown-menu { width: 100%; }

So I just used this code with ngb-typeahead- as the ID:

::ng-deep [id^="ngb-typeahead-"]{ 
width: 100%!important; 
white-space: nowrap!important;
overflow: hidden!important;
text-overflow: ellipsis!important;} 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!