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.

Tomasz Brzezina
  • 1,452
  • 5
  • 21
  • 44

2 Answers2

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.

Blackhole
  • 20,129
  • 7
  • 70
  • 68
-1
<form-field required={{field.required}}></form-field>

Which resolves to

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

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

Code Whisperer
  • 22,959
  • 20
  • 67
  • 85
  • 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. – Chic Aug 26 '15 at 17:16