简体   繁体   中英

Angularjs with bootstrap ui-datepicker

How to control datepicker object to call open/close method of datepicker. how to get datepicker object in another angularjs directive.

** HTML **

<input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="dt" is-open="popup1.opened" datepicker-options="dateOptions" ng-required="true" close-text="Close" alt-input-formats="altInputFormats" picker-date />

Directive:

   module.directive('pickerDate', function() {
      return {
        restrict: 'A',
        priority: 1,
        require: 'ngModel',
        link: function(scope, element, attrs, ctrl) {
          console.log(ctrl)
          element.on('click', function() {                
          });
          // console.log();
        }
      };
    });

When element click, how to call a method of datepicker? Any help would be appreciated. Thanks.

In the html, you have is-open="popup1.opened" . So you can control this by changing the boolean value of $scope.popup1.opened .

$scope.popup1.opened = true; // open date picker
$scope.popup1.opened = false; // close date picker

If you want to change this when an element is clicked, you can use ng-click . For example :

<input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="dt" is-open="popup1.opened" datepicker-options="dateOptions" ng-required="true" close-text="Close" alt-input-formats="altInputFormats" picker-date />
<button type="button" ng-click="popup1.opened = !popup1.opened"></button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM