2016-11-27 84 views
0

我正在嘗試使用打字稿構建angularjs(angular 1.)項目的結構。 我正在使用webpack將打印稿編碼& ES6編譯爲javascript。如何在打字稿中導入angularjs子模塊

在我的項目我配置的WebPack只編譯「app.ts」文件,包括在所有其他文件與「進口」的語法:

import { config } from './config';///<--HERE 
    module angularSeed { 
    'use strict'; 

     // Declare app level module which depends on views, and components 
     angular.module('myApp', [ 
     'ngRoute', 
     'myApp.view1', 
     'myApp.view2', 
     'myApp.version' 
     ]).config(config)//<-- using imported config.ts 

    } 

我想我的項目拆分成角子模塊並納入主模塊類似以下內容:

angular.module('mainApp',['myApp.version','myApp.view1','myApp.view2']) 

的問題是:如何導出子模塊?

我迄今爲止發現的唯一方法是定義模塊定義文件作爲類:

class view1 { 
    constructor(){ 
    angular.module('myApp.view1', ['ngRoute']) 

    .config(['$routeProvider', ($routeProvider: angular.route.IRouteProvider) => { 
     $routeProvider.when('/view1', { 
     templateUrl: 'view1/view1.html', 
     controller: 'View1Ctrl' 
     }); 
    }]) 

    .controller('View1Ctrl', [() => { 

    }]); 
    } 

} 
export default view1; 

,並在主文件 - 使用「新的」火的構造:

import { config } from './config'; 
import view2 from './view2/view2'; 
import view1 from './view1/view1'; 
import version from './components/version/version'; 
module angularSeed { 
'use strict'; 
    new view2();///<-- HERE 
    new view1(); 
    new version(); 
    // Declare app level module which depends on views, and components 
    angular.module('myApp', [ 
    'ngRoute', 
    'myApp.view1', 
    'myApp.view2', 
    'myApp.version' 
    ]).config(config) 


} 

我有感覺有更準確的方法。 對嗎?

感謝

回答

0

我找到了答案找here

你可以離開聲明的邏輯,因爲它是

angular.module('myApp.view1', ['ngRoute']) 

.config(['$routeProvider', ($routeProvider: angular.route.IRouteProvider) => { 
    $routeProvider.when('/view1', { 
    templateUrl: 'view1/view1.html', 
    controller: 'View1Ctrl' 
    }); 
}]) 

.controller('View1Ctrl', [() => { 

}]); 

,並用簡單的導入:

import './view1/view1'; 

語法