Let's say I have a controller in an AngularJS web application that has a data array that stores objects that are very similar, but require a different template depending on the type member variable. For instance:
function fooCtrl($scope) {
$scope.bar = [
{"name": "example 1",
"type": "egType1",
"text": "Some example text"},
{"name": "example 2",
"type": "egType2",
"text": "Some example text"},
{"name": "example 3",
"type": "egType3",
"text": "Some example text"},
];
}
You can easily create a template for outputting data using the ng-repeat directive as follows:
<ul>
<li ng-repeat="item in bar">
{{item.name}}
<p>{{item.text}}</p>
</li>
</ul>
However, this will result in each item having the same display.
What is the best way to display all items in a panel when changing a template depending on the value of item.type?
source
share