jqueryangularjsangularjs-directiveangularjs-scope

Angularjs: open on focus and month picker feature to calendar?


How can I add open on focus feature(similar as Microsoft windows 7 calendar) to my calendar as given in demo where we using angular material version1.0.1, please help me with solution.

Thanks In advance.

Solution

  • You'd have to add a custom directive in that case:

    .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'
      };
    });

    And then:

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

    Taken from this github comment:

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