我不完全確定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();
}
});
這太棒了!感謝這個例子 –