2017-04-26 45 views
1

我想組織這樣我的角度代碼:如何以模塊化的方式在路由後面加載Angular代碼?

project/ 
    thing/ 
    thing.js 
    view.html 
    other_thing/ 
    other_thing.js 
    view.html 

然後我想包括路由基於網址參數是把東西撿回來:

$routeProvider 
    .when('/thing', { 
    templateUrl: 'thing/thing.html', 
    controller: 'thingController' 
    }) 
    .when('/other_thing', { 
    templateUrl: 'other_thing/other_thing.html', 
    controller: 'otherThingController' 
    }); 

$locationProvider.html5Mode(true); 

什麼,我缺少的是如何加載thingControllerotherThingController。如果我有50個不同的控制器,我不想在前面加載所有的控制器,我想等到客戶端實際訪問路由以加載js,類似於在用戶導航之前不加載templateUrl的方式那裏。

+0

有多種方法來實現延遲加載,從的WebPack和systemjs配置,像ocLazyLoad庫。 – Claies

+0

@Claries ocLaxyLoad和angularAMD用於延遲加載,他需要在url上使用這個東西。 –

回答

相關問題