【问题标题】:AngularJS: How to access input[date] min attribute within custom directive?AngularJS:如何在自定义指令中访问 input[date] min 属性?
【发布时间】:2015-05-24 14:57:04
【问题描述】:

我正在尝试在我的自定义指令值中获得<input type="date" min 属性的写入权限。 据我所知 input[date] 元素是指令。 https://docs.angularjs.org/api/ng/input/input%5Bdate%5D 所以通过 $(elem).attr('min') 访问不是正确的方法。 如何在我的指令中访问 input[date] min 属性?

JsFiddle 在这里:http://jsfiddle.net/musuk/Lbbtyjod/

【问题讨论】:

    标签: javascript angularjs angular-directive


    【解决方案1】:

    DEMO

    根据您的指示:

    使用attrs.myDirective 访问指令链接函数中的最小值。访问最小日期:attrs.min 并设置最小日期attrs.$set('min', '2015-03-02')

    .directive("myDirective", function(){
       return {
          require: 'ngModel',
           scope: {
               minValue: "=myDirective"
           },
          link: function(scope, element, attrs) {
              scope.$watch('minValue', function(){
                  console.log(attrs.myDirective);
                  // Set min here
                  attrs.$set('min', '2015-03-02');
              });
          }
        };
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-23
      • 1970-01-01
      相关资源
      最近更新 更多