Angularjs:打开日历的焦点和月份选择器功能?

问题描述 投票:0回答:1

如何将打开焦点功能(类似于 Microsoft Windows 7 日历)添加到我的日历中,如 demo 中所示,我们使用 Angular Material 版本 1.0.1,请帮助我解决方案。

Thanks In advance.
jquery angularjs angularjs-directive angularjs-scope
1个回答
0
投票

在这种情况下,您必须添加自定义指令:

.directive('openOnFocus', function () {

  function compile(tElement) {
    tElement.find('input').attr('ng-focus', 'ctrl.onFocus($event)');

    return function (scope, element, attrs, datePicker) {
      var focused = false;

      datePicker.onFocus = (event) => {
        focused = !focused;

        if(focused) {
          datePicker.openCalendarPane(event);
        }
      };
    };
  }

  return {
    compile: compile,
    priority: -1,
    require: 'mdDatepicker',
    restrict: 'A'
  };
});

然后:

<md-datepicker open-on-focus></md-datepicker>

摘自此 github 评论:

https://github.com/angular/material/issues/4650#issuecomment-191930096

© www.soinside.com 2019 - 2024. All rights reserved.