- Ngx-Bootstrap 教程
- Ngx-Bootstrap - 首頁
- Ngx-Bootstrap - 概述
- Ngx-Bootstrap - 環境設定
- Ngx-Bootstrap - 手風琴
- Ngx-Bootstrap - 警報
- Ngx-Bootstrap - 按鈕
- Ngx-Bootstrap - 輪播
- Ngx-Bootstrap - 摺疊
- Ngx-Bootstrap - 日期選擇器
- Ngx-Bootstrap - 下拉選單
- Ngx-Bootstrap - 模態框
- Ngx-Bootstrap - 分頁
- Ngx-Bootstrap - 氣泡提示
- Ngx-Bootstrap - 進度條
- Ngx-Bootstrap - 評分
- Ngx-Bootstrap - 可排序
- Ngx-Bootstrap - 標籤頁
- Ngx-Bootstrap - 時間選擇器
- Ngx-Bootstrap - 工具提示
- Ngx-Bootstrap - 自動完成
- Ngx-Bootstrap 有用資源
- Ngx-Bootstrap - 快速指南
- Ngx-Bootstrap - 有用資源
- Ngx-Bootstrap - 討論
Ngx-Bootstrap - 時間選擇器
ngx-bootstrap 時間選擇器元件提供了一個易於使用且高度可配置的時間選擇器元件。
TimepickerComponent
選擇器
timepicker
輸入
arrowkeys − 布林值,如果為 true,則可以使用鍵盤上的向上/向下箭頭鍵更改小時和分鐘的值。
disabled − 布林值,如果為 true,則小時和分鐘欄位將被停用。
hoursPlaceholder − 字串,時間選擇器中小時欄位的佔位符。
hourStep − 數字,小時更改步長。
max − 日期,使用者可以選擇的最大時間。
meridians − 字串陣列,基於區域設定的子午線標籤。
min − 日期,使用者可以選擇的最小時間。
minutesPlaceholder − 字串,時間選擇器中分鐘欄位的佔位符。
minuteStep − 數字,小時更改步長。
mousewheel − 布林值,如果為 true,則小時和分鐘輸入內的滾動將更改時間。
readonlyInput − 布林值,如果為 true,則小時和分鐘欄位將為只讀。
secondsPlaceholder − 字串,時間選擇器中秒欄位的佔位符。
secondsStep − 數字,秒更改步長。
showMeridian − 布林值,如果為 true,則將顯示子午線按鈕。
showMinutes − 布林值,在時間選擇器中顯示分鐘。
showSeconds − 布林值,在時間選擇器中顯示秒。
showSpinners − 布林值,如果為 true,則將顯示輸入上方的和下方的微調箭頭。
輸出
isValid − 如果值為有效日期,則發出 true。
示例
由於我們將使用時間選擇器,因此我們需要更新 ngx-bootstrap 標籤章節中使用的 app.module.ts 以使用TimepickerModule。
更新 app.module.ts 以使用 TimepickerModule。
app.module.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 以使用時間選擇器元件。
test.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 以對應變數和方法。
test.component.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 {
}
}
構建和執行
執行以下命令以啟動 Angular 伺服器。
ng serve
伺服器啟動並執行後。開啟 https://:4200。點選“開啟模態”按鈕並驗證以下輸出。