码迷,mamicode.com
首页 > Web开发 > 详细

[AngularJS] Lazy Loading modules with ui-router and ocLazyLoad

时间:2015-01-04 06:24:36      阅读:1221      评论:0      收藏:0      [点我收藏+]

标签:

We‘ve looked at lazy loading with ocLazyLoad previously, but what if we are using ui-router and want to lazy load modules when we change states?

 

angular.module("demo", ["ui.router", "oc.lazyLoad"])
    .config(function ($stateProvider) {
        $stateProvider.state(‘store‘, {
            templateUrl: "store/store.html",
            controller: "StoreCtrl as store",
            resolve: {
                store: function ($ocLazyLoad) {
                    return $ocLazyLoad.load(
                        {
                            name: "store",
                            files: ["store/store.js"]
                        }
                    )
                }
            }
        })
    })

    .controller("AppCtrl", function ($state) {
        var app = this;
        app.click = function () {
            $state.go("store")
        }
    })

 

[AngularJS] Lazy Loading modules with ui-router and ocLazyLoad

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/4200265.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!