1

I am using datepicker in the tabset elements from angular bootstrap. When I am using datepicker inside the tab and on selecting the date I am not able to get correct value of selected date in controller.

If i am removing the tab then I am able to get the currently selected date. The code is in plunker: http://plnkr.co/edit/dIJRDQUYdrKmChdIt9T2?p=preview

 <form name="form" class="form-horizontal" ng-controller="ctrl">
    <tabset>
      <tab justified="true">
        <tab-heading>
          Main
        </tab-heading>
    <div class="form-group">
      <label class="col-xs-2 control-label" for="etaDate">ETA Date</label>
      <div class="input-group col-xs-6 col-sm-4 col-md-2">
        <input class="form-control" id="etaDate" name="etaDate" type="text" ng-model="eta" datepicker-popup="dd/MM/yyyy" is-open="opened.open" show-weeks="false" />
        <span class="input-group-btn">
              <button class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
            </span>
      </div>
    </div>
     <button ng-click="getdate()">GET DATE</button>
      </tab>
    </tabset>
  </form>

script.js

angular.module('myApp', ['ui.bootstrap']);
var ctrl = function($scope) {
  $scope.opened = {};

  $scope.open = function($event) {
    $event.preventDefault();
    $event.stopPropagation();
    $scope.opened.open = true;
  };
  $scope.eta = new Date();

  $scope.getdate = function (){
    alert($scope.eta)
  };

};
Moppo
  • 18,797
  • 5
  • 65
  • 64
anand
  • 1,711
  • 2
  • 24
  • 59

1 Answers1

0

Can find the working demo below with two tabs: http://embed.plnkr.co/RkLGqy5zZjfCqlCuuNPF/preview

"Tabset" directory creates its own isolated scope inside main scope with its own properties and will not inherit properties to parent. To over come this issue, As @charlietfl stated we should use dot (.) in ng-model.

For better understanding, please check the https://github.com/angular-ui/bootstrap/issues/1553#issuecomment-31980027

or

More briefly explained: https://stackoverflow.com/a/14049482/1252454

Community
  • 1
  • 1
Vidyadhar
  • 1,088
  • 9
  • 15