0

Is it possible to get conditional attribute (not class)?

e.g.:

<form-field {true: 'required'}[field.required]></form-field>

expected results

<form-field required></form-field>

or

<f orm-field ></form-field>

now I've got an

Error: The string contains invalid characters.

This is in html file not in template which I can compile.

2
  • Try using ng-attr-*. See this similar question. Commented Dec 28, 2013 at 14:18
  • It doesn't work in my case Commented Dec 28, 2013 at 14:45

2 Answers 2

3

No, it's not possible. In your case, you can of course use the ngRequired parameter of the input directive.

Inspired by this exemple, you can use a similar trick for your custom directives: just add a parameter that indicate whether or not the directive is enabled.

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

2 Comments

Yes, but i need it also for more attributes, the required was the simpliest example - but of course you're right
This is actually completely possible. See my answer.
-1
<form-field required={{field.required}}></form-field>

Which resolves to

<form-field required=true></form-field>

JSFiddle Example: http://jsfiddle.net/HB7LU/9973/

1 Comment

Your example doesn't work. I think the field is getting set to disable because it simply exists. If you change the $scope.disable variable to false, the field is still disabled.

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.