Angular 2: Timepicker for Material Design

Wer seine Anwendungen mit Angular 2 im Material Design entwickelt, verwendet dafür sehr wahrscheinlich Angular Material. Doch leider fehlt dort noch ein wichtige Komponente...

Erstellt in App-Engineering, Webentwicklung am

Anyone developing their applications using Angular 2 in material design will most likely use Angular Material. Finally, Angular material has excellent ready-to-use components that can greatly ease the craft of an Angular developer.

One of these components is, for example, the Datepicker:

material design datepicker

In the Material Design Guidelines there are examples of a timepicker, which have not yet been officially implemented in angular material:

Material Design Timepicker

Practically there is an unofficial implementation for the older Angular in version 1. Zhe software developer Steve Dunlap has ported this to Angular 5. Although this implementation is only an example and also includes only limited functions, which is why it fits only limited for your own projects, so we used his code and expanded it for our purposes. The timepicker is now responsive, the color can be determined, the clock is animated and the source code can now be easily integrated into your own projects.

Use

wTime

<w-time color="primary" [(userTime)]="exportTime" revertLabel="Revert" submitLabel="Submit" (onRevert)="onRevert()" (onSubmit)="onSubmit($event)"></w-time>

The HTML element w-time can display the clock directly, the attribute userTime binds the time to the component:

public exportTime = {hour: 7, minute: 15, meriden: 'PM'};

The labels of the buttons can be overwritten with the attributes revertLabel and submitLabel.

The attributes (onRevert) =" onRevert ()" and (onSubmit) = "onSubmit($event) execute the passed function as soon as one of the buttons are clicked, for example a snackbar can be triggered:

public onRevert() {
  this.exportTime = {hour: 7, minute: 15, meriden: 'PM'};
  this.snackBar.open(`Revert time to ${this.exportTime.hour}:${this.exportTime.minute} ${this.exportTime.meriden}`, null, {
    duration: 500,
  });
}

public onSubmit(time) {
  this.snackBar.open(`Saved time ${this.exportTime.hour}:${this.exportTime.minute} ${this.exportTime.meriden}`, null, {
    duration: 500,
  });
}

And so it looks like now:

wMatTimepicker

Like the Datepicker, there is a component that can be used in a similar way:

<w-mat-timepicker color="primary" [(userTime)]="exportTime"></w-mat-timepicker>

With a click on the clock a dialog opens and the clock can be selected accordingly:

With the demonstrations you can also experiment directly in the browser.

Future

In the future we plan to make some improvements to the timepicker. Our recent changes as a pull request have been submitted to Steve Dunlap so he can merge our improvements into his original project and he or other developers can continue to improve it . For us it's a nice example of open source software, everyone benefits :)

We hope the module will help you, have fun.

Newsletter

Melde dich für unseren Newsletter an

Impressum

Wir lieben OpenSource
Daher ist der Quellcode dieser Seite steht jedem frei zur Verfügung und auf Github zu finden.
JumpLink network logo

Angaben gem. § 5 TMG

Betreiber und Kontakt
Pascal Garber
Kasernenstraße 8
27472 Cuxhaven DE

Telefon
+49 152 54 09 01 89
Fax
+49 4721­ 664319
E-Mail
info@jumplink.eu
USt-IdNr.
DE277453808

Verantwortliche/r i.S.d. § 55 Abs. 2 RStV
Pascal Garber, Bei der Kirche 12, 27476 Cuxhaven
JumpLink

JumpLink ist ein Netzwerk aus selbstständigen Designern und Programmierern.

Datenschutz
Die Datenschutzerklärung findest Du unter https://jumplink.eu/en/datenschutzerklarung

Online-Streitbeilegung gemäß Art. 14 Abs. 1 ODR-VO
Die Europäische Kommission stellt eine Plattform zur Online-Streitbeilegung (OS) bereit: https://ec.europa.eu/consumers/odr/.
Wir sind zur Teilnahme an einem Streitbeilegungsverfahren vor einer Verbraucherschlichtungsstelle weder verpflichtet noch bereit.

Mitglied der Initiative "Fairness im Handel".
Informationen zur Initiative: fairness-im-handel.de