@alexfriesen/ngx-mat-timepicker

中文文档
19.0.1发布于 2024/12/17MITTypeScriptES Module近 30 天下载 2010

ngx-mat-timepicker is an Angular material 17+ extension to add time pickers!

原始使用文档
文档目录8 节
  1. Table of contents
  2. Getting started
  3. Internationalization
  4. Theming
  5. Documentation
  6. Demo
  7. License
  8. Thanks to

@alexfriesen/ngx-mat-timepicker

npm MIT licensed Build state Size

A simple time picker module using Angular Material: it provides an Android style dialog for time selection and a handy input for time selection in Material style.

ngx-mat-datepicker preview

Table of contents

Getting started

Install timepicker through npm:

npm i --save @alexfriesen/ngx-mat-timepicker

Next import the timepicker module into your app's module:

import { NgModule } from '@angular/core';
import { NgxMatTimepickerModule } from '@alexfriesen/ngx-mat-timepicker';

@NgModule({
  imports: [NgxMatTimepickerModule],
})
export class MyModule {}

Finally connect the timepicker to an input via a template property:

<input [ngxMatTimepicker]="picker" />
<ngx-mat-timepicker #picker />

The timepicker opens once you click on the input

Internationalization

Timepicker supports locales in format BCP 47. It has en-US locale by default.

To override default locale:

import { NgModule } from '@angular/core';
import { NgxMatTimepickerModule } from '@alexfriesen/ngx-mat-timepicker';

@NgModule({
  imports: [NgxMatTimepickerModule.setLocale('en-GB')],
})
export class MyModule {}

Theming

This Package relies on an existing Angular Material Theme:

@import '@angular/material/prebuilt-themes/indigo-pink.css';

or

@use '@angular/material' as mat;

@include mat.all-component-themes($my-theme);

Documentation

API reference for Angular Material Timepicker

import { NgxMatTimepickerModule } from '@alexfriesen/ngx-mat-timepicker';

NgxMatTimepicker

Directive responsible for managing the timepicker popup and setting value to input

Selector: ngxMatTimepicker

Properties

NameDescription
@Input() ngxMatTimepicker: NgxMatTimepickerComponentThe timepicker that this input is associated with.
@Input() color: ThemePaletteThe material palette to use.
@Input() disabled: booleanWeather the timepicker popup should be disabled.
@Input() value: stringSet a default value and time for a timepicker. The format of the time is in 12 hours notation 11:00 PM or in 24 hours notation 23:00. A Date string won't work.
@Input() format: number12 or 24 . 12h/24h view for hour selection clock . 12 (AM/PM) format by default.
@Input() min: string or DateTimeSet min time for timepicker (11:15 pm )
@Input() max: string or DateTimeSet max time for timepicker (11:15 pm )
@Input() disableClick: booleanSet true to disable opening timepicker by clicking on the input

NgxMatTimepickerLocaleService

This service allows to change the locale anytime.
You can inject this in your component or extend and provide your version, in order to provide your current locale to all the pickers!
At this time is semi-static, which means you can't change the locale for pickers that are already opened.
But new pickers will always get the updated locale.

NgxMatTimepickerComponent

Component responsible for visualisation the timepicker

Selector: ngx-mat-timepicker

Properties

NameDescription
@Input() cancelBtnTmpl: TemplateRefSet if you want to change cancel button to your custom one.
@Input() confirmBtnTmpl: TemplateRefSet if you want to change confirm button to your custom one.
@Input() editableHintTmpl: TemplateRefSet if you want to change dial hint to your custom one. Works only if enableKeyboardInput = true
@Input() ESC: booleanDisable or enable closing timepicker by ESC.
@Input() enableKeyboardInput: booleanTo disable or enable changing time through a keyboard on the timepicker dial without interaction with a clock face. Set false by default
@Input() minutesGap: numberTo define a gap between minutes. Set 1 by default
@Input() defaultTime: stringSet default time for a timepicker. 12:00 AM by default
@Input() preventOverlayClick: booleanSet true to prevent closing the timepicker by overlay click. Uses false by default
@Input() disableAnimation: booleanSet true to prevent opening and closing timepicker animation. Uses false by default
@Input() hoursOnly: booleanSet true to prevent switching to minutes automatically once hour is selected. Uses false by default
@Input() theme: NgxMatTimepickerThemeCustom css properties which will override the defaults
@Input() timepickerClass: stringTo provide a custom css class for the timepicker
@Output() timeSet: EventEmitter<string>Emits time when that was set.
@Output() opened: EventEmitter<null>Emits after timepicker was opened.
@Output() closed: EventEmitter<null>Emits after timepicker was closed.
@Output() hourSelected: EventEmitter<number>Emits after hour was selected.
@Output() timeChanged: EventEmitter<string>Emits once time was changed.

NgxMatTimepickerFieldComponent

The timepicker as a control.

Selector: ngx-mat-timepicker-field

Properties

NameDescription
@Input() disabled: booleanWhether the timepicker is disabled
@Input() floatLabel: 'never' or 'always' or 'auto'Whether the labels of the fields should float, default to never
@Input() toggleIcon: TemplateRef<HTMLObjectElement>Provide custom svg icon for toggle button
@Input() buttonAlign: 'right' or 'left'Positioning toggle button (right by default)
@Input() clockTheme: NgxMatTimepickerThemeCustom css properties which will override timepicker clock
@Input() controlOnly: booleanHide or display toggle button with the timepicker clock
@Input() format: number12 or 24 . Set format for timepicker. 12 (AM/PM) format by default.
@Input() cancelBtnTmpl: TemplateRef<Node>Set if you want to change cancel button for timepicker to your custom one.
@Input() confirmBtnTmpl: TemplateRef<Node>Set if you want to change confirm button for timepicker to your custom one.
@Input() min: string or DateTimeSet min time for timepicker (11:15 pm )
@Input() max: string or DateTimeSet max time for timepicker (11:15 pm )

| @Output()
timeChanged: EventEmitter<string> | Emit a new time once it is changed. |

NgxMatTimepickerToggleComponent

Component responsible for opening the timepicker.

Selector: ngx-mat-timepicker-toggle

Properties

NameDescription
@Input() for: NgxMatTimepickerComponentTimepicker instance that the button will toggle
@Input() disabled: booleanWhether the toggle button is disabled

NgxMatTimepickerToggleIconDirective

Can be used to override the icon of a NgxMatTimepickerToggleComponent.

Selector: [ngxMatTimepickerToggleIcon]

Properties

NameDescription
@Input() ngxMatTimepickerTheme: NgxMatTimepickerThemeCustom css properties which will override the defaults

Demo

Demo

$ npm
$ npm start

Run npm test to run tests once.

License

This project is licensed under the MIT License - see the LICENSE file for details

Thanks to

LayZeeDK - For his great work on the unit tests and upgrades for v15 "legacy"

Agranom for setting up the original repo.

版本与发布记录

@alexfriesen/ngx-mat-timepicker 共发布 11 个版本,首次发布于 2023/11/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
19.0.1latest2024/12/171.9 年前
19.0.02024/12/171.9 年前
19.0.0-beta.0beta2024/12/161.9 年前
18.0.22024/06/132 年前
18.0.12024/06/032 年前
18.0.02024/05/302 年前

关于 @alexfriesen/ngx-mat-timepicker 的常见问题

@alexfriesen/ngx-mat-timepicker 是什么?

ngx-mat-timepicker is an Angular material 17+ extension to add time pickers!

如何安装 @alexfriesen/ngx-mat-timepicker?

在项目目录运行 npm install @alexfriesen/ngx-mat-timepicker,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/animations(^19.0.0)、@angular/cdk(^19.0.0)、@angular/common(^19.0.0)、@angular/compiler(^19.0.0)、@angular/core(^19.0.0)、@angular/forms(^19.0.0)、@angular/material(^19.0.0)、@angular/platform-browser(^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@alexfriesen/ngx-mat-timepicker 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@alexfriesen/ngx-mat-timepicker 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@alexfriesen/ngx-mat-timepicker 可以商用吗?

@alexfriesen/ngx-mat-timepicker 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@alexfriesen/ngx-mat-timepicker 的下载量有多少?

根据 npm 官方下载统计,@alexfriesen/ngx-mat-timepicker 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,010 次,日均约 67 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alexfriesen/ngx-mat-timepicker 还在维护吗?

最新版本 19.0.1 发布于 2024/12/17(1.9 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/11/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。