- Ngx-Bootstrap 教程
 - Ngx-Bootstrap - 主页
 - Ngx-Bootstrap - 概述
 - Ngx-Bootstrap - 环境设置
 - Ngx-Bootstrap - 手风琴
 - Ngx-Bootstrap - 警报
 - Ngx-Bootstrap - 按钮
 - Ngx-Bootstrap - 轮播
 - Ngx-Bootstrap - 折叠
 - Ngx-Bootstrap - DatePicker
 - Ngx-Bootstrap - 下拉菜单
 - Ngx-Bootstrap - 模态框
 - Ngx-Bootstrap - 分页
 - Ngx-Bootstrap - 弹出窗口
 - Ngx-Bootstrap - 进度条
 - Ngx-Bootstrap - 评级
 - Ngx-Bootstrap - 可排序
 - Ngx-Bootstrap - 选项卡
 - Ngx-Bootstrap - 时间选择器
 - Ngx-Bootstrap - 工具提示
 - Ngx-Bootstrap - Typeahead
 - Ngx-Bootstrap 有用资源
 - Ngx-Bootstrap - 快速指南
 - Ngx-Bootstrap - 有用的资源
 - Ngx-Bootstrap - 讨论
 
Ngx-Bootstrap - TimePicker
ngx-bootstrap timepicker 组件提供了一个易于使用且高度可配置的时间选择器组件。
时间选择器组件
选择器
时间选择器
输入
arrowkeys - 布尔值,如果为 true,则可以使用键盘上的向上/向下箭头键更改小时和分钟的值。
禁用- 布尔值,如果为真,则小时和分钟字段将被禁用。
hoursPlaceholder - 字符串,时间选择器中小时字段的占位符。
hourStep - 数字,小时变化步长。
max - 日期,用户可以选择的最大时间。
meridians - string[],基于区域设置的经络标签。
min - 日期,用户可以选择的最短时间。
minutesPlaceholder - 字符串,时间选择器中分钟字段的占位符。
分钟步- 数字,小时变化步长。
mousewheel - 布尔值,如果为 true,则在小时和分钟内滚动输入将更改时间。
readonlyInput - 布尔值,如果为 true,小时和分钟字段将是只读的。
SecondsPlaceholder - 字符串,时间选择器中秒字段的占位符。
SecondStep - 数字,秒改变步长。
showMeridian - 布尔值,如果为真则显示子午线按钮。
showMinutes - 布尔值,在时间选择器中显示分钟。
showSeconds - 布尔值,在时间选择器中显示秒数。
showSpinners - 布尔值,如果为 true,将显示输入上方和下方的旋转箭头。
输出
isValid - 如果值是有效日期,则发出 true。
例子
由于我们要使用 TimePicker,我们必须更新ngx-bootstrap Tabs章节中使用的 app.module.ts 以使用TimepickerModule。
更新 app.module.ts 以使用 TimepickerModule。
应用程序模块.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { TestComponent } from './test/test.component';
import { AccordionModule } from 'ngx-bootstrap/accordion';
import { AlertModule,AlertConfig } from 'ngx-bootstrap/alert';
import { ButtonsModule } from 'ngx-bootstrap/buttons';
import { FormsModule } from '@angular/forms';
import { CarouselModule } from 'ngx-bootstrap/carousel';
import { CollapseModule } from 'ngx-bootstrap/collapse';
import { BsDatepickerModule, BsDatepickerConfig } from 'ngx-bootstrap/datepicker';
import { BsDropdownModule,BsDropdownConfig } from 'ngx-bootstrap/dropdown';
import { PaginationModule,PaginationConfig } from 'ngx-bootstrap/pagination';
import { PopoverModule, PopoverConfig } from 'ngx-bootstrap/popover';
import { ProgressbarModule,ProgressbarConfig } from 'ngx-bootstrap/progressbar';
import { RatingModule, RatingConfig } from 'ngx-bootstrap/rating';
import { SortableModule, DraggableItemService } from 'ngx-bootstrap/sortable';
import { TabsModule, TabsetConfig } from 'ngx-bootstrap/tabs';
import { TimepickerModule } from 'ngx-bootstrap/timepicker';
@NgModule({
   declarations: [
      AppComponent,
      TestComponent
   ],
   imports: [
      BrowserAnimationsModule,
      BrowserModule,
      AccordionModule,
      AlertModule,
      ButtonsModule,
      FormsModule,
      CarouselModule,
      CollapseModule,
      BsDatepickerModule.forRoot(),
      BsDropdownModule,
      ModalModule,
      PaginationModule,
      PopoverModule,
      ProgressbarModule,
      RatingModule,
      SortableModule,
      TabsModule,
      TimepickerModule.forRoot()
   ],
   providers: [AlertConfig, 
      BsDatepickerConfig, 
      BsDropdownConfig,
      BsModalService,
      PaginationConfig,
      ProgressbarConfig,
      RatingConfig,
      DraggableItemService,
      TabsetConfig],
   bootstrap: [AppComponent]
})
export class AppModule { }
更新 test.component.html 以使用 timepicker 组件。
测试.component.html
<timepicker [(ngModel)]="time"></timepicker>
<pre class="alert alert-info">Time is: {{time}}</pre>
<timepicker [(ngModel)]="time" [showMeridian]="false"></timepicker>
<pre class="alert alert-info">Time is: {{time}}</pre>
更新 test.component.ts 中相应的变量和方法。
测试组件.ts
import { Component, OnInit } from '@angular/core';
@Component({
   selector: 'app-test',
   templateUrl: './test.component.html',
   styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
   time: Date = new Date();
   constructor() {}
   ngOnInit(): void {
   } 
}
构建和服务
运行以下命令启动角度服务器。
ng serve
服务器启动并运行后。打开http://localhost:4200。单击“打开模式”按钮并验证以下输出。
