2

I have a list which can contain different types of things that need a different template / controller. Whats the best way to do this in angular js.

The best i've come up with so far is to have the template as part of the ng-repeat data.

<ul>
  <li ng-repeat="foo in list">
    <div ng-include src="'partials/'+foo.template+'.template.html'">
    </div>
  </li>
</ul>

where the list is something like.

[{template:'foo',data:{...}},{template:'bar',data:{...}}]

2 Answers 2

1

Looks good to me, you don't even need the <div> tags since you can attach ng-include to the <li> tags (I think).

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

Comments

0

You can use a directive like this http://onehungrymind.com/angularjs-dynamic-templates/

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.