简体   繁体   English

在Angular 4中更改NgbDatepicker的大小

[英]Change size of NgbDatepicker in Angular 4

For some reason unknown to me, my NgbDatePicker is much smaller than I want it to be. 由于某些我不知道的原因,我的NgbDatePicker比我想要的要小得多。 It currently displays at the following size: 它目前显示为以下大小:

在此输入图像描述

...when I was expecting it to display at the size in the example found here ...当我希望它显示在这里找到的示例中的大小时

One weird thing that I noticed is that the following portion of the datepicker in my application has the attribute _ngcontent-c0 set on its div: 我注意到一个奇怪的事情是我的应用程序中的_ngcontent-c0的以下部分在其div上设置了属性_ngcontent-c0

在此输入图像描述

...meanwhile the exact same portion of the example found on the website has the attribute _ngcontent-c4 set on its div. ...同时在网站上找到的示例的完全相同部分在其div上设置了属性_ngcontent-c4 This means that their divs aren't even the same. 这意味着他们的div甚至不一样。 This same attribute is also used in several css selectors. 同样的属性也用在几个css选择器中。

This is the code in which I make the datepicker appear. 这是我在其中显示日期选择器的代码。 I make it appear when an input field is clicked: 单击输入字段时显示:

<form class="form-inline">
  <div class="form-group">
    <div class="input-group">
      <input readonly class="form-control rounded" (click)="d.toggle()" (clickOutside)="onDocumentClick($event, d)" (ngModelChange)="onModelChanged($event)" placeholder="yyyy-mm-dd"
             name="dp" [(ngModel)]="model" ngbDatepicker #d="ngbDatepicker">
      <svg><use xlink:href="sprite.svg#calendar"></use></svg>
    </div>
  </div>
</form>

This is the ngOnInit() code of the component that configures the DatePicker: 这是配置DatePicker的组件的ngOnInit()代码:

    ngOnInit(): void {
    let today = new Date();
    let todayInDateStruct = {day: today.getUTCDate(), month: today.getUTCMonth() + 1, year: today.getUTCFullYear()};
    this.config.maxDate = this.maxDate || todayInDateStruct;
    this.config.minDate = this.minDate || {year: 1900, month: 1, day: 1};

    if (this.minDate$) {
        Rx.on(this, this.minDate$, (minDate: NgbDateStruct) => {
            if (minDate) {
                this.config.minDate = minDate;
            }
        });
    }

    /*
     The following line sets the first day of the week on the Calendar to Sunday instead of the default Monday.

     source: https://ng-bootstrap.github.io/#/components/datepicker/api
     */
    this.config.firstDayOfWeek = 7;
    }

Is there any way of increasing the size of the NgbDatepicker without overriding several NgbDatepicker styles? 有没有办法增加NgbDatepicker的大小而不重写几个NgbDatepicker样式?

I think u can use this. 我想你可以用这个。 create a custom template, for example: 创建自定义模板,例如:

 <ng-template #tpl let-date="date" let-currentMonth="currentMonth" let-selected="selected"> <div class="day">{{ date.day }} </div> </ng-template> 

then set the dayTemplate property: [dayTemplate]="tpl" 然后设置dayTemplate属性: [dayTemplate]="tpl"

and CSS: 和CSS:

 .day { text-align: center; padding: 7px; border-radius: 1rem; width: 100% !important; } .ngb-dp-day{ width: 100% !important; height: 100% !important; } .ngb-dp-weekday{ width: 100% !important; height: 100% !important; } 

the padding is distance between day and day. 填充是白天和白天之间的距离。 because the default css for dayview and weekday is "width: 2rem, height: 2rem" so you need to modify it by add "!important". 因为dayview和weekday的默认css是“width:2rem,height:2rem”,所以你需要通过添加“!important”来修改它。

add " encapsulation: ViewEncapsulation.None " into your component 将“ encapsulation:ViewEncapsulation.None ”添加到组件中

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

相关问题 Angular 使用 ngbdatepicker 抛出 RangerError: 超出最大调用堆栈大小 - Angular using ngbdatepicker throwing RangerError: Maximum call stack size exceeded 如何更改角度动力bootstrap ngbDatepicker的模型结构 - How to change model structure of angular powered bootstrap ngbDatepicker 如何在角度引导程序的ngbDatepicker输入字段中更改日期格式? - How to change date format in ngbDatepicker input field in angular bootstrap? Angular NgbDatepicker 移动问题 - Angular NgbDatepicker mobile issue Angular NgbDatepicker 部分隐藏 - Angular NgbDatepicker partially hidden Angular Reactive 形式的 ngbDatepicker - ngbDatepicker in Angular Reactive Form 是否可以动态更改ngbDatepicker格式化程序? - Is it possible to change ngbDatepicker formatter dynamically? 如何将NgbDatePicker格式从YYYY-MM-DD更改为MM-DD-YYYY角4? - how to change NgbDatePicker format from YYYY-MM-DD to MM-DD-YYYY angular 4? Angular bootstrap ngbdatepicker 删除(更改)方法所以是否有其他选项可以读取控制器上的模型值 - Angular bootstrap ngbdatepicker removing (change) method so Is there any other option to read model value on controller 使用打字稿中的 Angular 关闭 ngbDatePicker 弹出窗口 - Close a ngbDatePicker popup with Angular from the typescript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM