0

I am trying to get to grips with directives and am struggling with one aspect. The expression in the form input element of a directive is not being evaluated when used in an attribute which is also a directive.

Consider this element which is part of the directives HTML,

<input name="atin" type="text" ng-model="model" required="{{req}}" random-attribute="{{req}}"/>

Assuming the value of the attribute value "req" (passed in via an isolate scope attribute) is "true", then when the directive has been compiled/linked the resultant HTML (when you view the source) is

<input name="atin" type="text" ng-model="model" required="{{req}}" random-attribute="true"/>

I.e. it has only been substituted in the "random-attribute", but not the "required" attribute. I am guessing this has something to do with the fact that the required attribute is itself a directive.

Here is a plunkr which demonstrates it

http://plnkr.co/edit/sq5lpbKqjyV9mCOwSBTo

I do know of one solution which involves adding the input elements attributes during the compile stage of the atInput directive, but I would like to know why this current solution does not work and what is the best way to solve this problem.

Thanks

1 Answer 1

0

Sounds like you might need to do ng-required="req" instead of required="{{req}}"...

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

Comments

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.