我的方法是完全分离客户端和服务器端。
一个演示插件: http ://plnkr.co/edit/5cFLo3wLfbL0bUnifJe5?p=preview
服务器应该只关心资源:
app.get('/api/setup', function(req,res){
var setup = // something
res.json(setup);
})
客户端可以在获取数据后推迟引导:
基于这个答案:在手动引导之前使用角度服务
angular.bootstrap().invoke(function($http){
$http.get('/api/setup').then(function(res){
// providing the fetched data to the module:
angular.module('yourApp').constant('setup', res.data)
// manual bootstraping
angular.bootstrap(document,['yourApp']);
})
});
setup
然后你可以在你的模块中注入:
app.config(function(setup){
// constants can be injected to config blocks
})
app.controller('ctrl',function(setup){
// do what you need
})
如果您需要启动画面,请查看我的答案: 使用 ng-cloak 创建启动画面