Angular2 ClockPicker

I am currently exploring all alternatives to clockpicker for a web application working with Angular 2

Something like http://weareoutman.imtqy.com/clockpicker/ for example.

I have done research, but everything seems to be not easy to set up.

Has anyone found a suitable solution?

Thank!

+4
source share
1 answer

1st step

Use angular client ( https://github.com/angular/angular-cli ) to create a new project:

ng new clockpicker-example

2nd step

Install the necessary packages:

npm install jquery --save-dev

npm install jquery --save-dev

npm install clockpicker --save-dev

npm install @types/clockpicker --save-dev

Third step

Inside .angular-cli.json:

"styles": [
    "styles.css",
    "../node_modules/bootstrap/dist/css/bootstrap.min.css",
    "../node_modules/clockpicker/dist/bootstrap-clockpicker.min.css"
 ],
 "scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js",
    "../node_modules/clockpicker/dist/bootstrap-clockpicker.min.js"
  ],

4th step

create a file named clockpicker.directive.ts

import {Directive, ElementRef, OnInit} from "@angular/core";
@Directive({
   selector: '[appClockPicker]'
})


export class ClockPickerDirective implements OnInit {
   constructor(private el: ElementRef) {}

   ngOnInit(): void {
     $(this.el.nativeElement).clockpicker({
       placement: 'bottom',
       align: 'left',
       donetext: 'Done',
       afterDone: () => {
         console.log('done');
       }
     });
   }
}

5th step

Inside app.component.html:

<div class="input-group" appClockPicker>
  <input type="text" class="form-control" value="09:30">
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-time"></span>
  </span>
</div>

6th step

Inside typings.d.tsadd:

declare var $: any;
declare var jQuery: any;
+2
source

Source: https://habr.com/ru/post/1674647/


All Articles