Yuva Raj
Yuva Raj

Reputation: 3881

Pre Select Year in Angular JS Date Picker in Year format

I've a date picker and set the mode to Year to choose an year. I've year values like 2016, 1994 etc. If I set these values in ng-model of that date picker input, it throws the error & shows wrong year.

Also, I want only the Year value when the Year Selected.

JS code :

$scope.open = function() {
      $scope.opened = true;
  };

  $scope.yu = 2200;

  $scope.dateOptionsForYear={
    showWeeks: false,
    datepickerMode : 'year',
    minMode : 'year'  
  }

HTML :

<input type="text" placeholder="Year" ng-model="yu" uib-datepicker-popup="yyyy"
   ng-click="open()"
   class="form-control" 
   is-open="opened" show-button-bar="false"
   datepicker-options="dateOptionsForYear"/>

I've set up a Plunker. Here's the link!

Upvotes: 0

Views: 420

Answers (1)

Naveen Asapu
Naveen Asapu

Reputation: 37

make the code to

$scope.yu = 2200;

to

$scope.yu = new Date("1994"); 

Upvotes: 1

Related Questions