I embed search results directly into a HTML page to save a round trip. Currently I do the following:
<script>
var embeddedResults = { /* rendered by server */ };
var app = angular.module("MyApp", []);
app.controller("MyController", ["$scope", function($scope) {
$scope.results = embeddedResults;
// ...
}]);
</script>
What is the proper way of doing this? Also: does this way allow me to put the embeddedResults variable at the very end of the page i.e., even after the controller definition?
embeddedResultsat the bottom of the page? If you are rendering from the server, I don't see a reason to do the assignment directly in the controller body e.g.$scope.results = { /* rendered by server */ };. If you want your controller to fully load before the results are assigned, you could use $timeout e.g.$timeout(function() { $scope.results = { /* rendered by server */ }; })resultsarray to be able to 1) test the controller more easily and 2) put the controller andembeddedResultsvariable into different files.