2016-12-17 60 views
0

如何在我的日曆上添加open on focus功能(與Microsoft Windows 7日曆相似),如demo中我們使用angular materiel version1.0.1所示,請幫助我解決問題。Angularjs:在日曆上打開焦點和月份選擇器功能?

Thanks In advance. 
+0

您可以更新到Angular Material 1.1.1嗎?如果是這樣,您可以將'md-open-on-focus'指令添加到datepicker中。 – Jpod

+0

感謝您的迴應,我如何在不更新角度材料1.1.1的情況下做到這一點? – user7303839

回答

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

+0

感謝您的努力,請您指出它的工作示例。它不能按預期演示工作(http://plnkr.co/edit/dbR7K1bngMaF7iO4S09o?p=preview)..日曆圖標必須是可點擊的1.1.1((material.angularjs.org/latest/demo/datepick er ))版本日曆是可點擊的,當我們點擊(十二月2016)它給幾個月和很快......但你的演示不? – user7303839

+0

當您點擊日曆圖標時,鏈接中的日曆看起來像是打開的?不知道是什麼問題 – Jpod

+0

爲它增加了新的問題http://stackoverflow.com/questions/41250474/how-to-extend-datepicker-directive-with-monthpicker-in-calendar-pane請看看 – user7303839

相關問題