2016-11-27 22 views
0

typescriptを使用してangularjs(angular 1.)プロジェクトの構造を構築しようとしています。 私はタイプパック& ES6をjavascriptにコンパイルするためにwebpackを使用しています。私のプロジェクトでtypescriptでangularjsサブモジュールをインポートする方法

私は唯一の「app.ts」ファイルおよび他のすべてのファイルをコンパイルするのWebPACKを設定し、「インポート」構文でそれに含ま:私は私のプロジェクトは、角のサブモジュールに分割することにしたい

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'; 

構文

関連する問題