如何以角度查找页面加载时间?

Sha*_*mar 5 angular-ui-router angular

这是在 angular2+ 中找到页面加载时间的正确方法吗??我不这么认为,这只是路由变化的时间差。如何将页面DOM内容加载时间添加到其中。??

this.router.events.subscribe((val) => {
    const navigationComplete = val instanceof NavigationEnd;
    const navigationStart = val instanceof NavigationStart;
    if(navigationStart){
        this.navigationStartTime = (new Date).getTime();
    }
    if (navigationComplete) {
        this.currentPage = this.router.url; // Current page route
        this.currentLocation = (this.platformLocation as any).location.href; // Current page url
        let endTime = (new Date).getTime();
        this.pageLoadTime = Number(endTime) - Number(this.navigationStartTime); // Page load time
    }
});
Run Code Online (Sandbox Code Playgroud)

man*_*mar 2

您绝对可以使用 chrome 开发工具来分析性能,如 @AurA
在上述所有可以初始化的脚本中单独提到的

<script type="text/javascript">
    var timerStart = Date.now();
</script>
Run Code Online (Sandbox Code Playgroud)

并在主要组件中

ngAfterViewInit(){
   console.log("Time until reaching run phase: ", Date.now() - $window.timerStart);
}
Run Code Online (Sandbox Code Playgroud)

没有测试过。但应该跑。