【问题标题】:uib-datepicker-popup not working in my angular appuib-datepicker-popup 在我的 Angular 应用程序中不起作用
【发布时间】:2017-09-02 04:33:18
【问题描述】:

uib-datepicker-popup 在我的 Angular 应用程序中不起作用,我在其他控制器中工作

<input ng-click="open($event, 'delivery_time_popup')" type="text" class="form-control" uib-datepicker-popup="dd-MMMM-yyyy" show-weeks="false" ng-model="purchase_order.delivery_time" is-open="delivery_time_popup" datepicker-options="dateOptions" required close-text="Close" placeholder="Select Date">

JS

$scope.open = function ($event, opened) {
        console.log(opened);
        $event.preventDefault();
        $event.stopPropagation();
        $scope[opened] = true;
    };

    $scope.delivery_time_popup = false;

    $scope.dateOptions = {
        formatYear: 'yy',
        startingDay: 1
    };

【问题讨论】:

  • 控制台显示什么?
  • delivery_time_popup
  • 尝试将uib-datepicker-popup="dd-MMMM-yyyy"更改为uib-datepicker-popup

标签: javascript angularjs datepicker angular-ui-bootstrap


【解决方案1】:

您需要在open 函数中将$scope.delivery_time_popup 的值更改为true。

 $scope.open = function ($event, opened) {
    console.log(opened);
    $event.preventDefault();
    $event.stopPropagation();
    $scope[opened] = true;

    $scope.delivery_time_popup = true; //add this
};

在您的 html 中将 ng-click 更改为 ng-focus

Plnkr example

HTML

<input ng-focus="open($event, 'delivery_time_popup')" type="text" class="form-control" uib-datepicker-popup="dd-MMMM-yyyy" show-weeks="false" ng-model="purchase_order.delivery_time" is-open="delivery_time_popup" datepicker-options="dateOptions" required close-text="Close" placeholder="Select Date">

控制器

$scope.open = function ($event, opened) {
    console.log(opened);
    $event.preventDefault();
    $event.stopPropagation();
    $scope[opened] = true;

    $scope.delivery_time_popup = true;
};

   $scope.delivery_time_popup = false;

   $scope.dateOptions = {
    formatYear: 'yy',
    startingDay: 1
    };
});

【讨论】:

  • 试过但没有成功
  • 首先,您的 ng-click 是在输入文本上,它需要在按钮上,或者 ng-click 必须是 ng-focus
  • ng-focus 正在工作,但日期选择器弹出窗口未出现
  • 检查更新答案,并查看 plknr 示例。
  • 分享您的完整控制器和视图
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-01
  • 2018-11-22
  • 1970-01-01
  • 1970-01-01
  • 2017-04-17
相关资源
最近更新 更多