Given an HTML template
<div class="info">
<div class="title"><a href="property-detail.html">{{title}}</a></div>
<div class="location">{{location}}</div>
<div class="property-info clearfix">
<div class="area"><i class="icon icon-normal-cursor-scale-up"></i>{{size}}<sup>2</sup></div>
<div class="bedrooms"><i class="icon icon-normal-bed"></i>{{bedrooms}}</div>
<div class="bathrooms"><i class="icon icon-normal-shower"></i>{{bathrooms}}</div>
</div><div class="price">{{price}}</div>
<div class="link">
<a href="{{details}}">View more</a>
</div>
</div>
And a model that fits this template (that is, has all the fields: title, location, price, etc.). I am looking for a way to programmatically bind the template to the model and then push the rendered results to an array. In pseudo-code I am looking to do something like that:
var boxes= [];
for (var i = 0; i < items.length; i++) {
var results = bind(template, items[i]);
boxes.push(results);
}
Where items is an array of items which i got from the database or any other source, and bind is basically the function that is responsible to populate the template with the model.
It makes sense to use a directive. Not sure how to do that though.
Any idea if and how it can be done using Angular?
<my-dir data-item="item" ng-repeat="item in boxes"></my-dir>and you would need to put boxes on the scope... If your template url needs to be dynamic based on some static situation then you can as well use templateUrl as a function that returns a templateName.. based on some attributes on the element