简体   繁体   English

angular 的 ngx-bootstrap - 日期选择器当似乎没有任何效果时如何更改主题颜色

[英]ngx-bootstrap for angular - datepicker how do i change the theme color when nothing seems to work

I'm trying to change the color of the datepicker and it is not working我正在尝试更改日期选择器的颜色,但它不起作用

Here is the ngx-bootstrap datepicker https://valor-software.com/ngx-bootstrap/#/datepicker这是 ngx-bootstrap 日期选择器https://valor-software.com/ngx-bootstrap/#/datepicker

This is my html template这是我的 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>

I was trying various things, I do realize that this applyTheme is a function我正在尝试各种事情,我确实意识到这个 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();
  });
}

You are not calling that function. 你没有调用那个功能。 Do this instead 这样做

  1. Add a call in your input html element input html元素中添加一个调用

     [bsConfig]="dpConfig" 

Next add to component above constructor 接下来添加到构造函数上面的组件

public dpConfig: Partial<BsDatepickerConfig> = new BsDatepickerConfig();

Inside constructor: 内部构造函数:

this.dpConfig.containerClass = 'theme-dark-blue'; //or whatever color

Add the following lines in global styling file: styles.scss 在全局样式文件中添加以下行: 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; 
}

Adding [bsConfig]="{containerClass:'theme-default'}" to my component html file works fine for me. [bsConfig]="{containerClass:'theme-default'}"到我的组件html文件中对我来说很好。

The input element after addition of theme configuration: 添加主题配置后的输入元素:

<input type="text"
        placeholder="Select Time"
        class="form-control"
        bsDatepicker
        [bsConfig]="{containerClass:'theme-default'}"
        [(ngModel)]="startDateTime" (ngModelChange)="onStartDateTimeChange($event)">

I am using ngx-bootstrap version 3.2.0 with Angular 7.2.4 我使用ngx-bootstrap版本3.2.0与Angular 7.2.4

Add the following line in angular.json styles在 angular.json styles 添加如下行

          "./node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",

We can directly go to bs-datepicker.config.js file and there just change: 我们可以直接转到bs-datepicker.config.js文件,只需更改:

this.containerClass = 'theme-dark-blue';

or whatever color you want. 或者你想要的任何颜色。

-> ngx bootstrap DatePicker -> ngx 引导程序 DatePicker

component.ts (Set DatePicker configurations) component.ts(设置日期选择器配置)

//ngxBootstrap datePicker config
bsConfig:Partial<BsDatepickerConfig> = {
  containerClass:'theme-red',
  dateInputFormat:'DD MMM YYYY'
}

template.html模板.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.

相关问题 NGX-Bootstrap/Angular - 分页 - 当我的屏幕视图(宽度)发生变化时无法更改 maxSize 输入 - NGX-Bootstrap/Angular - Pagination - cannot change the maxSize input when my screen view (width) is changing ngx-bootstrap提前输入,带FormControl angular 2 - ngx-bootstrap typeahead with FormControl angular 2 Angular ui-bootstrap datepicker更改主题 - Angular ui-bootstrap datepicker change theme 使用多个引导模式(ngx-bootstrap 和 Angular)时遇到问题 - Trouble using multiple bootstrap modals (ngx-bootstrap and Angular) 在Angle 5中使用ngx-bootstrap typeahead和模型值数组 - using ngx-bootstrap typeahead in angular 5 with an array of model values Ngx-bootstrap工具提示:手动更改位置值 - Ngx-bootstrap Tooltip : Change manually postion values 当模态高度为动态滚动时的 ngx-bootstrap 不会出现 - ngx-bootstrap when modal height is dynamic scroll is not coming ngx-bootstrap carousel - 如何修改指标,提高可访问性 - ngx-bootstrap carousel - how to modify indicators, improve accessibility 如何使用 ngx-bootstrap 甚至在禁用的按钮上显示工具提示 - How to show the Tooltip even on disabled buttons with ngx-bootstrap 如何在异步httpclient调用中使用ngx-bootstrap typeahead - How to use ngx-bootstrap typeahead with async httpclient call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM