Improve this Doc  View Source

input[week]

  1. - input in module ng

Input with week-of-the-year validation and transformation to Date. In browsers that do not yet support the HTML5 week input, a text element will be used. In that case, the text must be entered in a valid ISO-8601 week format (yyyy-W##), for example: 2013-W02.

The model must always be a Date object, otherwise Angular will throw an error. Invalid Date objects (dates whose getTime() is NaN) will be rendered as an empty string.

The timezone to be used to read/write the Date instance in the model can be defined using ngModelOptions. By default, this is the timezone of the browser.

Directive Info

  • This directive executes at priority level 0.

Usage

<input type="week"
       ng-model="string"
       [name="string"]
       [min="string"]
       [max="string"]
       [ng-min=""]
       [ng-max=""]
       [required="string"]
       [ng-required="string"]
       [ng-change="string"]>

Arguments

Param Type Details
ngModel string

Assignable angular expression to data-bind to.

name
(optional)
string

Property name of the form under which the control is published.

min
(optional)
string

Sets the min validation error key if the value entered is less than min. This must be a valid ISO week format (yyyy-W##). You can also use interpolation inside this attribute (e.g. min="{{minWeek | date:'yyyy-Www'}}"). Note that min will also add native HTML5 constraint validation.

max
(optional)
string

Sets the max validation error key if the value entered is greater than max. This must be a valid ISO week format (yyyy-W##). You can also use interpolation inside this attribute (e.g. max="{{maxWeek | date:'yyyy-Www'}}"). Note that max will also add native HTML5 constraint validation.

ngMin
(optional)
datestring

Sets the min validation constraint to the Date / ISO week string the ngMin expression evaluates to. Note that it does not set the min attribute.

ngMax
(optional)
datestring

Sets the max validation constraint to the Date / ISO week string the ngMax expression evaluates to. Note that it does not set the max attribute.

required
(optional)
string

Sets required validation error key if the value is not entered.

ngRequired
(optional)
string

Adds required attribute and required validation constraint to the element when the ngRequired expression evaluates to true. Use ngRequired instead of required when you want to data-bind to the required attribute.

ngChange
(optional)
string

Angular expression to be executed when input changes due to user interaction with the input element.

Example

<script>
angular.module('weekExample', [])
  .controller('DateController', ['$scope', function($scope) {
    $scope.example = {
      value: new Date(2013, 0, 3)
    };
  }]);
</script>
<form name="myForm" ng-controller="DateController as dateCtrl">
  <label>Pick a date between in 2013:
    <input id="exampleInput" type="week" name="input" ng-model="example.value"
           placeholder="YYYY-W##" min="2012-W32"
           max="2013-W52" required />
  </label>
  <div role="alert">
    <span class="error" ng-show="myForm.input.$error.required">
        Required!</span>
    <span class="error" ng-show="myForm.input.$error.week">
        Not a valid date!</span>
  </div>
  <tt>value = {{example.value | date: "yyyy-Www"}}</tt><br/>
  <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
  <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
  <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
  <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
</form>