All Projects → samuelnygaard → ng2-timezone-selector

samuelnygaard / ng2-timezone-selector

Licence: MIT License
A simple Angular module to create a timezone selector using moment-timezone.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to ng2-timezone-selector

Angular4-seed
Angular 4 Seed for Angular Forms
Stars: ✭ 37 (+208.33%)
Mutual labels:  angular2, angular4, angular-2, angular5
discord-clock
A simple clock script for your bot to show what time it is in your server | Discord.js v13 ready!
Stars: ✭ 29 (+141.67%)
Mutual labels:  moment, momentjs, moment-js, moment-timezone
ngx-redux-core
The modern redux integration for Angular 6+
Stars: ✭ 32 (+166.67%)
Mutual labels:  angular2, angular4, angular5
ng2-acl
Role based permissions for Angular v2++
Stars: ✭ 15 (+25%)
Mutual labels:  angular2, angular4, angular-2
angular-rollbar-source-maps
Angular 2+ implementation to upload sourcemaps to Rollbar
Stars: ✭ 17 (+41.67%)
Mutual labels:  angular2, angular4, angular5
moment-dayjs-codemod
A Codemod to migrate from moment.js to day.js
Stars: ✭ 20 (+66.67%)
Mutual labels:  moment, momentjs, moment-js
AuthGuard
Example repo for guarding routes post
Stars: ✭ 42 (+250%)
Mutual labels:  angular2, angular4, angular5
laravel5Angular4
Laravel 5.4 & Angular 4.3.4
Stars: ✭ 37 (+208.33%)
Mutual labels:  angular2, angular4, angular-2
Angular5 Seed
Angular5 Seed for Application
Stars: ✭ 222 (+1750%)
Mutual labels:  angular2, angular4, angular5
spring-websocket-angular6
Example for using Spring Websocket and Angular with Stomp Messaging
Stars: ✭ 18 (+50%)
Mutual labels:  angular2, angular4, angular5
ncg-crud-ngx-md
Angular 4+ Material Design CRUD/Admin app by NinjaCodeGen http://DNAfor.NET
Stars: ✭ 36 (+200%)
Mutual labels:  angular2, angular4, angular-2
angular-landing-page
Beautiful Angular landing page with firebase, chat, poll, dynamic features/gallary, and nice animations/scrolling.
Stars: ✭ 43 (+258.33%)
Mutual labels:  angular2, angular4, angular5
Ng Select
⭐ Native angular select component
Stars: ✭ 2,781 (+23075%)
Mutual labels:  angular2, angular4, angular5
Friend-Time
Discord bot - Friend Time helps your server coordinate times and events by converting times mentioned in chat between time zones!
Stars: ✭ 62 (+416.67%)
Mutual labels:  timezone, momentjs, timezones
Ng Drag Drop
Drag & Drop for Angular - based on HTML5 with no external dependencies. 🎉
Stars: ✭ 233 (+1841.67%)
Mutual labels:  angular2, angular4, angular5
ng-toggle
Bootstrap-styled Angular Toggle Component
Stars: ✭ 14 (+16.67%)
Mutual labels:  angular2, angular4, angular5
Angular Google Maps
Angular 2+ Google Maps Components
Stars: ✭ 1,982 (+16416.67%)
Mutual labels:  angular2, angular4, angular5
Ngx Daterangepicker Material
Pure Angular 2+ date range picker with material design theme, a demo here:
Stars: ✭ 169 (+1308.33%)
Mutual labels:  angular2, angular4, angular5
format-date
📆 A small library (around 400 B when gziped & minified) to format JavaScript `Date` object using same tokens as moment.
Stars: ✭ 25 (+108.33%)
Mutual labels:  moment, momentjs, moment-js
moment-recur-ts
Conversion of the moment-recur library into TypeScript.
Stars: ✭ 17 (+41.67%)
Mutual labels:  moment, momentjs, moment-js

ng2-timezone-selector

A simple Angular module to create a timezone selector using moment-timezones.

Demo | Documentation

New features (0.2.3)

  • Guess the timezone based on browser settings, usage:
    • <ng2-timezone-picker [(timezone)]="timezone" guess="true"></ng2-timezone-picker>
  • Show GMT offset (equivalent with UTC offset), e.g.: Denmark (GTM+01:00), usage:
    • <ng2-timezone-picker [(timezone)]="timezone" showOffset="true"></ng2-timezone-picker>
  • Select timezone based on country iso code and outputs country iso code based on timezone, usage:
    • <ng2-timezone-picker [(timezone)]="timezone" [(country)]="countryIsoCode"></ng2-timezone-picker>

Installation

To install this library, run:

$ npm install ng2-timezone-selector --save

Requirements (IMPORTANT, use one of the following methods)

The library depent on jQuery and select2 and moment-timezone

The only file required is the select2 select2.min.css file:

1. Method (should work for all)

Include the select2.min.css file in the angular-cli.json file (remember to re-run ng serve, after editing angular-cli.json):

{
  "project": {
    ...
  },
  "apps": [
    {
      ...
      "styles": [
        "styles.scss",
        "../node_modules/select2/dist/css/select2.min.css"
      ],
      ...
    }

2. Method (simplest)

If the angular project is setup to use *.scss instead of *.css, then you can add the following @import to the default *.scss file, othen called: styles.scss:

@import '~select2/dist/css/select2.min.css';

3. Method (HTML-link)

Include the css resource from a CDN link in the index.html file:

<head>
  ...
  <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
  ...
</head>

Importing

Import the module in app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

// Import the library
import { TimezonePickerModule } from 'ng2-timezone-selector';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    ...,
    // Include the library in the imports section
    TimezonePickerModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage

Once the library is imported, you can use the component in your Angular application:

<!-- You can now use the library component
 in app.component.html with double-binding: -->
<ng2-timezone-picker
    [(timezone)]="user.timezone"
    [placeholder]="placeholderString">
</ng2-timezone-picker>
<!-- You can now use the library component in
 app.component.html or with single-binding and a change function  -->
<ng2-timezone-picker
    [timezone]="user.timezone"
    (change)="changeTimezone($event)"
    placeholder="Select timezone"
    showOffset="true"
    guess="true">
</ng2-timezone-picker>
// Example of usage in app.component.ts:
user = {};
placeholderString = 'Select timezone';

changeTimezone(timezone) {
  this.user.timezone = timezone;
}

Parameters

Component configuration

You can configure component with the following input attributes:

  • timezone: string - Required: must be defined. The timezone string. If you are using the Two-Way Data Binding [(timezone)]="timezoneString" it will change on selection of timezone.
  • placeholder: string - Optional: default = ''. The placeholder string to show when no timezone is selected.
  • disabled: boolean - Optional: default = false. Disable the the component.
  • showOffset: boolean - Optional: default = false. Condition to show GMT offset in the dropdown.
  • guess: boolean - Optional: default = false. If set to true and if the timezone parameters is null or undefined then guesses the users timezone.
  • country: string - Optional. The country iso-string (e.g. 'US' / 'GB' / 'AU'). If you are using the Two-Way Data Binding e.g.: [(country)]="countryIsoCode" it will change the timezone to the provided iso-code (if the iso code is valid), and if the timezone is changed it changes the value of countryIsoCode to the iso of the country.
  • allowClear: boolean - Optional: default = false. Enabled you to clear the selection of a timezone.

You can configure component with the (change)="changeFunction($event) or (countryChange)="countryIsoCode = $event output attributes:

  • change: function($event) - Trigger-function when timezone is selected or changed, the $event parameter is the timezone string.
  • countryChange: function($event: string) - Trigger-function when timezone is changed, the $event parameter is the country iso-code.

License

MIT © Samuel Nygaard

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].