我想時間(秒)從當用戶導航到一個頁面需要多長時間,到結果通過$http
要求攝像時刻需要更新視圖中Angularjs
編輯:我顯示這個時候給用戶,類似於谷歌如何搜索後顯示他們
我的代碼如下所示:
UI視圖
個<div>
<h2>Awesome Surfers Directory</h2>
<!-- Display time it took to fetch and display all servers -->
<small>Results returned in {{ executionTime }} seconds</small>
<!-- Surfer List -->
<ul>
<li ng-repeat="surfer in surfers">
{{ surfer.firstName + ' ' + surfer.lastName }}
</li>
</ul>
</div>
JS
.state({
name: 'surfers',
url: '/getSurfers',
templateUrl: 'resources/components/surfers.html',
controller: function($scope, $http){
// Lets keep track of how long the fetch takes with a timer
var t0 = performance.now();
$http.get('fetchAllSurfers')
.then(function(response){
// Bind the results to scope - This could be several hundred results
$scope.surfers = response.data;
})
.catch(function(error){
// Oh no!
console.warn('Woah dude, something like went totally wrong and stuff')
})
.finally(function(){
// End the timer & bind to scope
var t1 = performance.now();
$scope.executionTime = (((t1 - t0) % 60000)/1000).toFixed(1);
})
}
});
,定時器就會結束的請求完成,但在此之前還有衝浪者實際上是在查看/ UI(我假設是因爲角將顯示一段時間來更新DOM)。我只想知道如何在我的計時器中準確捕捉到這一點?
任何提示或幫助表示讚賞!
爲什麼不通過瀏覽器 - >'Network'? –
@MaximShoustin我將此時間顯示給用戶 –