2

angularjs で日付フィールドをオートフォーカスしようとしています。そのためのディレクティブを作成しましたが、問題なく動作していますが、問題が発生しています。右側にあるアイコンをクリックしない限り、HTML5 日付ピッカーは開きません。

(function () {
  "use strict";

  angular
    .module("ctraUIComponents")
    .directive("inputAutoFocus", autoFocus);

  /**
   * @ngInject
   * @return {{restrict: string, link: autoFocusLink}}
   */
  function autoFocus ($timeout) {
    /**
     * @type {{restrict: string, link: autoFocusLink}}
     */
    var directive = {
      restrict: "A",
      link: autoFocusLink
    };

    return directive;

    /**
     * @ngInject
     * @param scope
     * @param element
     */
    function autoFocusLink (scope, element) {
      $timeout(function() {
        element[0].focus();
      });
    }
  }
})();

オートフォーカスで日付ピッカーを開く方法と、入力フィールドのどこかをクリックしたときに日付ピッカーを開く方法を教えてください。

ありがとう

4

1 に答える 1

0

`

<div layout-gt-xs="row">
    <div flex-gt-xs>
      <h4>Opening the calendar when the input is focused</h4>
      <md-datepicker ng-model="ctrl.myDate" md-placeholder="Enter date" md-open-on-focus></md-datepicker>
    </div>
</div>

`

angular.module('MyApp', ['ngMaterial', 'ngMessages', 'material.svgAssetsCache']).controller('AppCtrl', function() { this.myDate = new Date(); this.isOpen = false; });

より多くの例については、このAngular JSマテリアルの例のリンクに従ってください

于 2020-11-09T07:59:33.917 に答える