I have my angular.js app built with a php page that contains a variable that my app needs on load. The angular app on load then uses this variable to fetch more data using a POST. What is the best practice for passing a variable to angular? Also, how can I tell angular to not run the initial controller function until after it has the variable loaded? Thanks in advance.
2 Answers
In your case probably the best way is to write it down with something like this:
<script type="text/javascript">
var _yourSpecialVar = <?php echo $variable ?>;
</script>
And in Angular:
$window._yourSpecialVar
EDIT:
For example in an Angular controller:
angular.module('app').controller('YourController', ['$scope', '$window', function($scope, $window) {
$scope.myVar = $window._yourSpecialVar
}]);