在Angular NG-Bootstrap中使用日期选择器(DatePicker)可以按照以下步骤进行操作:
npm install --save @ng-bootstrap/ng-bootstrap
imports
部分,导入NgbModule
:import { NgModule } from '@angular/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@NgModule({
imports: [NgbModule],
exports: [NgbModule]
})
export class YourModule { }
import { Component } from '@angular/core';
import { NgbDateStruct, NgbCalendar } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-your-component',
template: `
`
})
export class YourComponent {
selectedDate: NgbDateStruct;
constructor(private calendar: NgbCalendar) {}
ngOnInit() {
this.selectedDate = this.calendar.getToday();
}
}
这样,你就可以在NG-Bootstrap的日期选择器中选择日期了。注意,在上面的示例中,我们使用了ngbDatepicker
指令来创建日期选择器,并使用NgbDateStruct
来存储所选的日期。