title: AngularJS directive for inputs described via objects
body: <p>I need to be able to display inputs based on an array of objects that describe them.
  For example, this describes 2 inputs foo and bar:</p>
  <pre><code>$scope.z.inputs = [{
    name: &quot;foo&quot;,
    hint: &quot;Enter foo number.&quot;,  // if hint is specified, it should be in a tooltip
    min: &quot;2&quot;, // this is optional
    max: &quot;100&quot; // this is optional
  }, {
    name: &quot;bar&quot;
  }];
  </code></pre>
  <p>See plunkr: <a href="http://plnkr.co/edit/giWusNpiRhHibJi3hr2e?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/giWusNpiRhHibJi3hr2e?p=preview</a>
  It has a crude directive that works with static inputs. It can't handle the other inputs (foo and bar).  Comments above the directive describe the functionality it provides.</p>
  <p>What approach can be done to handle these inputs while keeping the extra functionality the directive provides?</p>
  <h3>What I tried...</h3>
  <p>Setting min=&quot;{{in.min}}&quot; on the input element results in the value in the linking function being the string &quot;{{in.min}}&quot;.
  I tried setting scope and using @ (see the answer at <a href="https://stackoverflow.com/questions/14050195/what-is-the-difference-between-and-in-directive-scope/14063373#14063373">What is the difference between &#39;@&#39; and &#39;=&#39; in directive scope in AngularJS?</a>).  However, I didn't understand how to &quot;use attr.$observe...&quot; as is mentioned.  And what I did try didnt work.
  Plus the variable bound to the input with ng-model didn't get updated anymore after setting the directive's scope.</p>
  <p>After reading about the ng-switch approach mentioned at <a href="https://stackoverflow.com/questions/17636100/angularjs-dynamic-directives">Angularjs dynamic directives</a>
  I tried ng-switch and ng-if.  I kept a ng-if for min in the plunkr.
  If I can avoid having to use ngswitch or ngif for things like min, max, and hint that would be helpful as it would be unwieldy with more attributes.</p>
  <h3>Update</h3>
  <p>In the plnkr, I got min and max to work using ng-if statements to handle all possible combinations. I needed to modify the check in the directive for min and max. Instead of checking whether a number is specified, just check whether the attribute is specified. If it is (even if an expresion), then leave it alone and it gets updated with the right value.</p>
  <p>I'd still like to be able to avoid the proliferation of ng-ifs if there's a way to do that.</p>