@@ -406,12 +406,6 @@ defaultModelOptions = new ModelOptions({
406406 * </example>
407407 *
408408 *
409- * ## Specifying timezones
410- *
411- * You can specify the timezone that date/time input directives expect by providing its name in the
412- * `timezone` property.
413- *
414- *
415409 * ## Programmatically changing options
416410 *
417411 * The `ngModelOptions` expression is only evaluated once when the directive is linked; it is not
@@ -423,8 +417,70 @@ defaultModelOptions = new ModelOptions({
423417 * Default events, extra triggers, and catch-all debounce values}.
424418 *
425419 *
420+ * ## Specifying timezones
421+ *
422+ * You can specify the timezone that date/time input directives expect by providing its name in the
423+ * `timezone` property.
424+ *
425+ *
426+ * ## Formatting the value of `time` and `datetime-local`
427+ *
428+ * With the options `timeSecondsFormat` and `timeStripZeroSeconds` it is possible to adjust the value
429+ * that is displayed in the control. Note that browsers may apply their own formatting
430+ * in the user interface.
431+ *
432+ <example name="ngModelOptions-time-format" module="timeExample">
433+ <file name="index.html">
434+ <time-example></time-example>
435+ </file>
436+ <file name="script.js">
437+ angular.module('timeExample', [])
438+ .component('timeExample', {
439+ templateUrl: 'timeExample.html',
440+ controller: function() {
441+ this.time = new Date(1970, 0, 1, 14, 57, 0);
442+
443+ this.options = {
444+ timeSecondsFormat: 'ss',
445+ timeStripZeroSeconds: true
446+ };
447+
448+ this.optionChange = function() {
449+ this.timeForm.timeFormatted.$overrideModelOptions(this.options);
450+ this.time = new Date(this.time);
451+ };
452+ }
453+ });
454+ </file>
455+ <file name="timeExample.html">
456+ <form name="$ctrl.timeForm">
457+ <strong>Default</strong>:
458+ <input type="time" ng-model="$ctrl.time" step="any" /><br>
459+ <strong>With options</strong>:
460+ <input type="time" name="timeFormatted" ng-model="$ctrl.time" step="any" ng-model-options="$ctrl.options" />
461+ <br>
462+
463+ Options:<br>
464+ <code>timeSecondsFormat</code>:
465+ <input
466+ type="text"
467+ ng-model="$ctrl.options.timeSecondsFormat"
468+ ng-change="$ctrl.optionChange()">
469+ <br>
470+ <code>timeStripZeroSeconds</code>:
471+ <input
472+ type="checkbox"
473+ ng-model="$ctrl.options.timeStripZeroSeconds"
474+ ng-change="$ctrl.optionChange()">
475+ </form>
476+ </file>
477+ * </example>
478+ *
426479 * @param {Object } ngModelOptions options to apply to {@link ngModel} directives on this element and
427- * and its descendents. Valid keys are:
480+ * and its descendents.
481+ *
482+ * **General options**:
483+ *
428484 * - `updateOn`: string specifying which event should the input be bound to. You can set several
429485 * events using an space delimited list. There is a special event called `default` that
430486 * matches the default events belonging to the control. These are the events that are bound to
@@ -457,6 +513,10 @@ defaultModelOptions = new ModelOptions({
457513 * not validate correctly instead of the default behavior of setting the model to undefined.
458514 * - `getterSetter`: boolean value which determines whether or not to treat functions bound to
459515 * `ngModel` as getters/setters.
516+ *
517+ *
518+ * **Input-type specific options**:
519+ *
460520 * - `timezone`: Defines the timezone to be used to read/write the `Date` instance in the model for
461521 * `<input type="date" />`, `<input type="time" />`, ... . It understands UTC/GMT and the
462522 * continental US time zone abbreviations, but for general use, use a time zone offset, for
@@ -465,6 +525,24 @@ defaultModelOptions = new ModelOptions({
465525 * Note that changing the timezone will have no effect on the current date, and is only applied after
466526 * the next input / model change.
467527 *
528+ * - `timeSecondsFormat`: Defines if the `time` and `datetime-local` types should show seconds and
529+ * milliseconds. The option follows the format string of {@link date date filter}.
530+ * By default, the options is `undefined` which is equal to `'ss.sss'` (seconds and milliseconds).
531+ * The other options are `'ss'` (strips milliseconds), and `''` (empty string), which strips both
532+ * seconds and milliseconds.
533+ * Note that browsers that support `time` and `datetime-local` require the hour and minutes
534+ * part of the time string, and may show the value differently in the user interface.
535+ * {@link ngModelOptions#formatting-the-value-of-time-and-datetime-local- See the example}.
536+ *
537+ * - `timeStripZeroSeconds`: Defines if the `time` and `datetime-local` types should strip the
538+ * seconds and milliseconds from the formatted value if they are zero. This option is applied
539+ * after `timeSecondsFormat`.
540+ * This option can be used to make the formatting consistent over different browsers, as some
541+ * browsers with support for `time` will natively hide the milliseconds and
542+ * seconds if they are zero, but others won't, and browsers that don't implement these input
543+ * types will always show the full string.
544+ * {@link ngModelOptions#formatting-the-value-of-time-and-datetime-local- See the example}.
545+ *
468546 */
469547var ngModelOptionsDirective = function ( ) {
470548 NgModelOptionsController . $inject = [ '$attrs' , '$scope' ] ;
0 commit comments