[英]NGX-Bootstrap/Angular - Pagination - cannot change the maxSize input when my screen view (width) is changing
[英]ngx-bootstrap for angular - datepicker how do i change the theme color when nothing seems to work
我正在嘗試更改日期選擇器的顏色,但它不起作用
這是 ngx-bootstrap 日期選擇器https://valor-software.com/ngx-bootstrap/#/datepicker
這是我的 html 模板
<div class="form-group">
<label class="col-sm-3 control-label" for="date">Date:</label>
<div class="col-sm-9">
<input type="text"
class="form-control"
[minDate]="minDate"
[maxDate]="maxDate"
#dp="bsDatepicker"
bsDatepicker [(bsValue)]="bsValue">
<button class="btn btn-success" (click)="dp.toggle()">Date Picker</button>
</div>
</div>
我正在嘗試各種事情,我確實意識到這個 applyTheme 是一個 function
colorTheme = 'theme-green';
bsConfig: Partial<BsDatepickerConfig>;
applyTheme(pop: any) {
// create new object on each property change
// so Angular can catch object reference change
this.bsConfig = Object.assign({}, { containerClass: this.colorTheme });
setTimeout(() => {
pop.show();
});
}
你沒有調用那個功能。 這樣做
在input
html元素中添加一個調用
[bsConfig]="dpConfig"
接下來添加到構造函數上面的組件
public dpConfig: Partial<BsDatepickerConfig> = new BsDatepickerConfig();
內部構造函數:
this.dpConfig.containerClass = 'theme-dark-blue'; //or whatever color
在全局樣式文件中添加以下行: styles.scss
.bs-datepicker-body table td.week span
{
color: #2dfbcd !important;
}
.bs-datepicker-body table td span.selected,
.bs-datepicker-head,
.bs-datepicker-head, .bs-datepicker button:active,
.bs-datepicker-body table td.selected span,
.bs-datepicker-body table td span[class*="select-"]:after,
.bs-datepicker-body table td[class*="select-"] span:after,
.bs-datepicker-body table td.active-week span:hover
{
background-color: #2dfbcd !important;
}
將[bsConfig]="{containerClass:'theme-default'}"
到我的組件html文件中對我來說很好。
添加主題配置后的輸入元素:
<input type="text"
placeholder="Select Time"
class="form-control"
bsDatepicker
[bsConfig]="{containerClass:'theme-default'}"
[(ngModel)]="startDateTime" (ngModelChange)="onStartDateTimeChange($event)">
我使用ngx-bootstrap版本3.2.0
與Angular 7.2.4
在 angular.json styles 添加如下行
"./node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
我們可以直接轉到bs-datepicker.config.js
文件,只需更改:
this.containerClass = 'theme-dark-blue';
或者你想要的任何顏色。
-> ngx 引導程序 DatePicker
component.ts(設置日期選擇器配置)
//ngxBootstrap datePicker config
bsConfig:Partial<BsDatepickerConfig> = {
containerClass:'theme-red',
dateInputFormat:'DD MMM YYYY'
}
模板.html
<input type="text" class="form-control" placeholder="Date Of Birth"
name="dateOfBirth" formControlName="dateOfBirth"
bsDatepicker [bsConfig]="bsConfig"
[ngClass]="{'is-invalid':f.dateOfBirth.touched && f.dateOfBirth.errors}">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.