加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在angularjs中处理页面加载时间

发布时间:2020-12-17 17:15:29 所属栏目:安全 来源:网络整理
导读:我是 angularjs的新手.我写了一个简单的网站代码.这里我正在加载index.php主索引页面本身的所有控制器. script src="app/components/productController.js"/script script src="app/components/categoryController.js"/scriptscript src="app/components/off
我是 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状态解决它…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读