I want to dynamically generate the HTML data on my webpage based on data driven values. Ie I want to load a list of environments, a list of models, and then for each model/environment combination, output a row of HTML based on this.
I have used ng-repeat in the past to use a JS collection in my controller to generate the results, ie for each item in the collection, output this block of HTML, which is effectively what I want to do here, albeit with two nested ng-repeats. eg
<tr ng-repeat="model in models">
<td>
<div ng-repeat="env in environments">
{{model.name}} {{env.name}}
</div>
</td>
</tr>
My problem though is that I have to call off asynchronously to a REST api to get this data, and so when that returns, it goes into the promise block to handle the results.
Eg
appService.init = function()
{
ComputeModelService.getModels()
.then(function (response, status, headers, config) {
$scope.models = response.data;
}
ComputeModelService.getEnvironments()
.then(function (response, status, headers, config) {
$scope.environments = response.data;
}
}
init()
How do I get the controller to load the data from the REST API in the background, have the UI show a "loading" cursor while it loads, and then render the dynamic HTML when both sets of data come back?