在angularjs中处理页面加载时间

前端之家收集整理的这篇文章主要介绍了在angularjs中处理页面加载时间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 angularjs的新手.我写了一个简单的网站代码.这里我正在加载index.PHP主索引页面本身的所有控制器.

<script src="app/components/productController.js"></script> 
<script src="app/components/categoryController.js"></script>
<script src="app/components/offersController.js" ></script>
<script src="app/components/CheckController.js"></script>
<script src="app/components/orderController.js"></script>

加载时间更长.有没有什么办法可以在我调用特定的HTML页面时加载这些控制器?我试图在offer.html嵌入offercontrolller它不工作!我怎么处理这个?

解决方法

您可以使用 ocLazyLoad.您所要做的就是配置哪个页面将使用哪些文件

如果你使用的是ui.router,lazyLoad在这里工作得很好就是一个在特定状态下加载文件的例子……

$stateProvider.state('index',{
  url: "/",// root route
  views: {
    "lazyLoadView": {
      controller: 'AppCtrl',// This view will use AppCtrl loaded below in the resolve
      templateUrl: 'partials/main.html'
    }
  },resolve: { // Any property in resolve should return a promise and is executed before the view is loaded
    loadMyCtrl: ['$ocLazyLoad',function($ocLazyLoad) {
      // you can lazy load files for an existing module
             return $ocLazyLoad.load('js/AppCtrl.js');
    }]
  }
});

此示例取自ocLazyLoad文档,如您所见,您将仅在此状态下加载AppCtrl.js,您可以想象您只能在所需状态下加载任何文件.

想想你只在一个页面中使用非常大的图表库,所以你要做的就是用你的ocLazyLoad状态解决它…

猜你在找的Angularjs相关文章