当使用ng-include作为父节点时,使用jquery禁用所有子元素的Angular指令不起作用

时间:2016-04-26 07:59:02

标签: jquery html angularjs angular-directive angularjs-ng-include

我有一个使用jquery来禁用div中所有子元素的指令。因为它是一个包含大量控件的大页面,所以我使用ng-include指向其他html标记。我遇到的问题是,在我的指令的jquery应用之后,我的div的内容以某种方式加载。我不能将字段集与ng-disabled一起使用,因为这个应用程序是专门为IE而设计的,IE不支持在字段集上禁用ng(是的......我知道......很难过,但这是公司政策)。

角度指令:

app.directive('jqDisable', function() {
  var linkFunction = function(scope, element, attributes) {
      $(element).find('*').attr("disabled", true);
  };

  return {
    link: linkFunction
  }

});

html标记:

  <div ng-include src="'schedulerOneTimeOccurence.html'" jq-disable="true">

  </div>

plunker链接:http://plnkr.co/edit/jc9eCA?p=preview

THX

2 个答案:

答案 0 :(得分:1)

您可以简单地移动您的指令: JQ-禁用=&#34;真&#34; 到&#39; schedulerOneTimeOccurence.html&#39;。

  <div class="form-horizontal" ng-controller="ctrl" jq-disable="true" >
    <input type="text" datepicker-popup="MM/dd/yyyy" ng-model="dt" is-open="opened" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="" ng-required="true" />
    <button class="btn" ng-click="open()"><i class="icon-calendar"></i></button>
    <button ng-click="btnclick()">click</button>
  </div>

plunker链接:http://plnkr.co/edit/QaCWcdnNyvnyMS2LLsbJ?p=preview

答案 1 :(得分:0)

我认为没有理由使用ng-incluce,为什么不使用templateUrl

<div jq-disable="true"></div>

并在你的指令中:

app.directive('jqDisable', function() {
  var linkFunction = function(scope, element, attributes) {
      $(element).find('*').attr("disabled", true);
  };

  return {
    link: linkFunction,
    templateUrl: 'schedulerOneTimeOccurence.html'
  }

});
相关问题