In this scenario, I need to initialize the data from an inline script, even though I know how to achieve this using a promise on an http request.
Currently, the controller is already defined in the header js:
var testModule = angular.module('myTestModule', []);
testModule.controller('testCtrl', function ($scope) {
$scope.data = [];
});
Below is the HTML that loads. Let's assume that the script part takes a significant amount of time to complete:
<div ng-app="myTestModule" ng-controller="testCtrl">
...
</div>
<script type="text/javascript">
setInitialData(['boo', 'far']);
</script>
If the inline script were loaded BEFORE the div with ng-app, everything would work fine. However, in this case, it might load after the controller has been instantiated. I want to avoid making an extra http request, but at the same time, I see the convenience of using a promise with an angular service.
Does anyone have suggestions on how to design the function setInitialData so that it can apply the data to the controller/scope?