嗯,问题是使用 encapsulation:ViewEncapsulation.None 和类似的类
.bs-datepicker-head button:nth-child(3){
display:none!important;
}
ViewEncapsultaion.None 的问题在于组件中的所有 .css 都会影响到所有应用程序。所以,最好写一个 .css 之类的
.custom .bs-datepicker-head button:nth-child(3){
display:none!important;
}
所以,如果我们使用 ViewEncapsultaion.None,只会影响具有“自定义”类的日期选择器。要使用自定义类创建 datePicker,您需要使用 [bsConfig]。
我写代码
我们的 .html
<div class="content">
<h4>datepicker should display current date:</h4>
<div class="row">
<div class="col-xs-12 col-12 col-md-4 form-group">
<input type="text"
class="form-control"
[minDate]="minDate"
[maxDate]="maxDate"
#dp="bsDatepicker" [bsConfig]="bsConfig"
bsDatepicker [(bsValue)]="myDateValue">
</div>
</div>
</div>
还有我们的组件
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None
})
export class AppComponent implements OnInit {
myDateValue: Date;
bsConfig: Partial<BsDatepickerConfig>;
ngOnInit() {
this.myDateValue = new Date();
//see that our class was "theme-green custom"
this.bsConfig = Object.assign({}, { containerClass: 'theme-green custom' });
}
}
你可以在stackblitz看到