I have an Angular app running on Express 4.0 and I would like to send some information to the front end on startup, when the index file is served but I didn't manage to figure out on which route I should do this.
Thanks!
I think you are looking for angular.module('...').run()
. Here's the documentation on modules in angular. See the section on Module Loading & Dependencies
. Also note you can only inject instances (not Providers) into .config
and .run
blocks.
You can use the AngularJS $http service to make a GET request on an express route, wich gives you some json with the data you are trying to use in your front end.
Use NgInit
<div ng-init="names=[{data: 'a'},{data: 'b'}]"></div>
With that line in the html you will have in the controller the $scope.names object so you can do whathever you want with that.
Put that data in the ng-init directive using one of the templates engines that express has.