simon-void / pikaday_datepicker_angular2

provides a datepicker as Angular2 component
Other
5 stars 6 forks source link

PikadayAngular2

Deprecated:

A Dart Datepicker for AngularDart v4 is available as a new package pikaday_datepicker_angular.

A Dart Datepicker usable as a AngularDart v3 component

screenshot

If you do find bugs or have feature requests please submit them to the issues Also see the changelog

Usage

html

Link to the Pikaday.js-js library (with it's css file) and the optional but highly advisable Moment.js library (for advanced date formating) in your index.html-file. Currently, you also need to import the pikaday_dart_helpers.js file from the Pikaday package:

Assuming you put these files into /web/jsLibs/ the imports look like this:

<link rel="stylesheet" href="https://github.com/simon-void/pikaday_datepicker_angular2/blob/master/jsLibs/pikaday.css">
<script src="https://github.com/simon-void/pikaday_datepicker_angular2/raw/master/jsLibs/moment.js"></script>
<script src="https://github.com/simon-void/pikaday_datepicker_angular2/raw/master/jsLibs/pikaday.js"></script>
<script src="https://github.com/simon-void/pikaday_datepicker_angular2/raw/master/packages/pikaday/pikaday_dart_helpers.js"></script>

Download a local copy of those libs, put them in or under the directory your index.html file is in, an link accordingly.

Angular2

Check out the example under web!

Import and use PikadayComponent into your AngularDart2 component:

import 'package:angular2/core.dart';
import 'package:pikaday_datepicker_angular2/pikaday_datepicker_angular2.dart';

@Component(
    selector: 'my-app',
    template: '''<h1>AngularDart2-datepicker</h1>
                 <pikaday [(day)]="selectedDay" format="DD-MM-YYYY"
                          minDate="2010-1-1" maxDate="2025-12-31"
                          firstDay="1">
                 </pikaday>
                 <div>selectedDay: {{selectedDay | date}}</div>''',
    directives: const [PikadayComponent]
)
class AppComponent {
  DateTime selectedDay = new DateTime(2016, 12, 14);
}

If you want to compile the example under web to js, you have to change the transformer configuration to

transformers:
### (default) configuration if this package should be used as a library (import) or if the app should be execute as Dart in Dartium
#- angular2
### configuration if example web folder should be compiled to js
- angular2:
    platform_directives:
    - 'package:angular2/common.dart#COMMON_DIRECTIVES'
    platform_pipes:
    - 'package:angular2/common.dart#COMMON_PIPES'
    entry_points: web/main.dart
- dart_to_js_script_rewriter

Basic/Vanilla Dart Usage

If you're looking for a datepicker within a plain Dart project (not with angular), check out the Pikaday package.

Angular2 component - Configuration

PikadayComponent has many useful options:

Common problems

<link rel="stylesheet" href="https://github.com/simon-void/pikaday_datepicker_angular2/blob/master/jsLibs/pikaday.css">
<script src="https://github.com/simon-void/pikaday_datepicker_angular2/raw/master/jsLibs/moment.js"></script>
<script src="https://github.com/simon-void/pikaday_datepicker_angular2/raw/master/jsLibs/pikaday.js"></script>
<script src="https://github.com/simon-void/pikaday_datepicker_angular2/raw/master/packages/pikaday/pikaday_dart_helpers.js"></script>

Authors

Thanks to David Bushell for writing Pikaday.js. Thanks to John Ryan for writing Pikaday.

Copyright © 2017 Stephan Schröder | BSD & MIT license