0

Question:

I would like to modify the parameter for ng-disabled via a directive on the same element so that

<my-custom-input ng-disabled = "ctrl.condition" my-global-disabled-condition>
</my-custom-input>

generates the same effect as

<my-custom-input ng-disabled = "ctrl.condition || someService.isWinterComing()">
</my-custom-input>

How can I use a directive to modify the parameters for ng-disable, ng-if and other directives? Manually adding the logic to each element would work of course but that would not be properly modularized code.

Update

I was using an isolated scope by accident which caused my compile-step to produce unexpected results.

Thus my question is a duplicate of

Add directives from directive in AngularJS

Community
  • 1
  • 1
H W
  • 2,556
  • 3
  • 21
  • 45
  • You linked to working answers, but instead of just doing the same you left out the important parts. Is there a reason for that? – a better oliver Nov 09 '16 at 14:25
  • if you refer to setting the `priority` and the flag for `terminal`, i tried to include those but the behaviour did not change at all (except that increasing the priority in combination with the manual call to $compile seem to cause directives like ng-model to malfunction). Since the reason to use those is preventing multiple compilation of the same directives and my impression is that the compilation of ng-disable should not be affected by these, i removed them in the above example. – H W Nov 09 '16 at 14:30
  • These properties are necessary. – a better oliver Nov 09 '16 at 14:41
  • No, since i have a working example now, I can confirm that they are not necessary in general. However you will probably want to include them most of the time anyways. Read the linked explanation on what they do and when you need to include them if you are interested http://stackoverflow.com/a/19228302/3967289 – H W Nov 09 '16 at 14:58
  • _"not necessary in general"_ Sure, but you wanted the directive to work in general and not only in this simple case: _"to modify the parameters for ng-disable, ng-if and other directives"_ – a better oliver Nov 09 '16 at 16:11

0 Answers0