我不完全确定ui路由器是如何工作的,但是如果它是$ routeProvider(或者您也使用$ routeProvider),那么您可以将控制器分配给“应用程序的标题”并让该控制器完成这项工作。
下面是它将如何工作的基本示例。 _handleLoad模拟轮询服务器,当完成时,您可以轻松地更改标头(或使用$ broadcast的网站其他部分)。使用$ routeProvider让用户在页面上继续执行HeaderCtrl的同时浏览网站。
http://plnkr.co/edit/EYqcjhX8kI1GmkYs5VZe?p=preview
app.controller('HeaderCtrl', function ($scope, $timeout) {
var _i = 0,
_handleLoad = function() {
console.log('checking..');
// TODO check the server here, fire the $timeout in the callback if the process isn't complete
if (_i == 3) {
$scope.loading = false;
_i = 0;
$scope.headerText = 'we have loaded something';
console.log('all done');
return;
}
_i += 1;
$timeout(_handleLoad, 1000);
};
$scope.headerText = 'click here to load something';
$scope.loading = false;
$scope.load = function() {
$scope.loading = true;
_handleLoad();
}
});
这太棒了!感谢这个例子 –