Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>An <code>ng-switch</code> (<a href="http://docs.angularjs.org/api/ng.directive%3angSwitch" rel="nofollow">docs</a>) can help you out here; something like this:</p> <pre class="lang-html prettyprint-override"><code>&lt;div ng-repeat="item in items"&gt; &lt;div ng-switch on="item.type"&gt; &lt;div ng-switch-when="int"&gt; &lt;input type="range" max="{{item.max}}" min="{{item.min}}" ng-model="item.value" /&gt; &lt;/div&gt; &lt;div ng-switch-when="text"&gt; &lt;textarea ng-model="item.value"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>[Update]</strong></p> <p>Since you mentioned you want to dynamically include a template based on the type, take a look at <code>ng-include</code> (<a href="http://docs.angularjs.org/api/ng.directive%3angInclude" rel="nofollow">docs</a>) which takes an Angular expression evaluating to a URL:</p> <pre class="lang-html prettyprint-override"><code>&lt;div ng-repeat="item in items"&gt; &lt;div ng-include="'input-' + item.type + '-template.htm'"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>If you don't like the inline string concatenation, you can use a controller method to generate the URL:</p> <pre class="lang-html prettyprint-override"><code>&lt;div ng-repeat="item in items"&gt; &lt;div ng-include="templatePathForItem(item)"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>The example on the <code>ngInclude</code> documentation page is pretty good.</p> <p>Note that the included template will be given a prototypal child scope of the current scope.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload