Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div ng-controller="AppCtrl as ctrl" ng-app="MyApp">
  <div layout="row">
    <md-input-container>
      <label>HH:mm</label>
      <input ng-model="ctrl.timeInput" time-input/>
    </md-input-container>
    <md-select data-ng-model="ctrl.ampm" placeholder="AM/PM">
      <md-option ng-repeat="ampm in ctrl.ampms" ng-value="ampm">{{ ampm }}</md-option>
    </md-select>
  </div>
  {{ ctrl.timeInput }} {{ ctrl.ampm }}
    <md-select ng-model="ctrl.ampm" placeholder="AM/PM">
      <md-option ng-repeat="ampm in ['AM', 'PM']" ng-value="ampm">{{ ampm }}</md-option>
    </md-select>

</div>


              
            
!

CSS

              
                
              
            
!

JS

              
                (function () {
  'use strict';
  angular.module('MyApp')
    .controller('AppCtrl', function() {
      var _this = this;
      _this.timeInput = "";
      _this.ampm = '';
    _this.ampms = ['AM', 'PM'];
    })
    .directive('timeInput', function() {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function(scope, element, attrs, controller) {
          var numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':'];
          var preValue = '';
          
          function ensureHttpPrefix(value) {
            if (value && preValue.length < value.length && value.length < 6) {
              var valueArray = value.split('');
              var numberOnlyArray = [];

              // accepts only numbers and colon
              for (var i = 0; i < valueArray.length; i++) {
                if (numbers.indexOf(valueArray[i]) >= 0) {
                  // Colon is accetable at the index at 1 and 2.
                  if (valueArray[i] === ':') {
                    if (i === 1 || i === 2) {
                      numberOnlyArray.push(valueArray[i]);
                    }
                  } else {
                    // Prevent placing number at index at 3
                    if (numberOnlyArray.length === 2) {
                      numberOnlyArray.push(':');
                      numberOnlyArray.push(valueArray[i]);
                    } else {
                      numberOnlyArray.push(valueArray[i]);
                    }
                  }
                }
              }

              if (numberOnlyArray[1] === ':') {
                numberOnlyArray.unshift('0');
              }
              if (numberOnlyArray.length === 2) {
                var hour = parseInt(numberOnlyArray[0]) * 10 + parseInt(numberOnlyArray[1]);
                if (hour > 12) {
                  numberOnlyArray[0] = '1';
                  numberOnlyArray[1] = '2';
                }
                numberOnlyArray.push(':');
              }
              if (numberOnlyArray.length === 4) {
                // When the first digit of minute is entered, automatically put 0 after that.
                numberOnlyArray[4] = 0;
              }
              if (numberOnlyArray.length === 5) {
                var min = parseInt(numberOnlyArray[3]) * 10 + parseInt(numberOnlyArray[4]);
                if (min >= 60) {
                  numberOnlyArray[3] = 5;
                  numberOnlyArray[4] = 9;
                }
              }
              preValue = value;
              controller.$setViewValue(numberOnlyArray.join(""));
              controller.$render();
              return numberOnlyArray.join("");
            } else {
              if (value.length > 5) {
                var sixthChar = value.slice(5, 6);
                if (numbers.indexOf(sixthChar) >= 0 && sixthChar !== ':') {
                  // When sixth character is the number, replace the last character
                  value = value.slice(0, 4) + sixthChar;
                } else {
                  value = value.slice(0, 5);
                }
              }
              preValue = value;
              controller.$setViewValue(value);
              controller.$render();
              return value;              
            }
          }
          controller.$formatters.push(ensureHttpPrefix);
          controller.$parsers.push(ensureHttpPrefix);
        }
    }
  });
})();

              
            
!
999px

Console