0

I have a directive that uses jquery to disable all child elements inside a div. Because it's a big page with a lot of controls, I am using ng-include to point to other html markups. The issue I'm encountering is that in some way the content of my div loads after my jquery from my directive applies. I cannot use fieldset with ng-disabled because this app is designed on purpose for IE and IE does not support ng-disabled on fieldset (yeah...I know...sad, but it's a company policy).

angular directive:

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

  return {
    link: linkFunction
  }

});

html markup:

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

  </div>

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

Thx

2 Answers 2

1

You can simply move your directive: jq-disable="true" to 'schedulerOneTimeOccurence.html'.

  <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 link: http://plnkr.co/edit/QaCWcdnNyvnyMS2LLsbJ?p=preview

Sign up to request clarification or add additional context in comments.

1 Comment

Do a console.log($(element).find('*')); inside jqDisable. You basically need to wait for the template to be included (async task) before you apply the directives. Simple way to fix this is, like this answer says, to use jq-disable inside the included template.
0

i see no reason to use ng-incluce, why not use templateUrl

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

and in your directive:

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

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

});

3 Comments

This will make the directive work only with this specific container, which is not so recommended
why it is isn't recommended? thats the hole concept of directives
This directive is for making the elements in container disable. and you want to make it reusable. it should be useful for any container. so.. for that kind of directive it's pretty bad practice to add templateUrl

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.