[英]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.