2016-03-25 6 views
4

マイバンドルのout.jsファイルは、main.jsとapp.component.jsモジュールを連結します。今、私はindex.htmlにSystemJSを使ってこのout.jsファイルをインポートします。実際には、メイン(.js)モジュールを呼び出す必要があります。SystemJS:バンドルファイルでSystem.importを修正します

私のバンドルファイルの内部モジュールをインポートする方法が不思議です。 System.import(バンドル内)のSystem.import(内部モジュールの)System.importをネストするのは正しい方法ですか?実際には動作していますが、これが問題ないかどうかはわかりません。

System.register('app.component', ['angular2/core'], function(exports_1, context_1) { 
    var __moduleName = context_1 && context_1.id; 
    .. 
}}; 

System.register('main', ['angular2/platform/browser', './app.component'], function(exports_1, context_1) { 
    var __moduleName = context_1 && context_1.id;  
    .. 
}}; 

答えて

4

out.js

index.htmlを

<script type="text/javascript" src="lib/out.js"></script> 

<script> 
    System.config({ 
     packages: { 
      lib: { 
       format: 'register', 
       defaultExtension: 'js' 
      } 
     } 
    }); 
    System.import('lib/out') 
      .then(function() { // ---Is this the way to do it?--- 
       System.import('/main'); 
      }, console.error.bind(console)); 
</script> 

実際には、あなたのout.jsファイルがSystem.registerを使用して名前を直接あなたのモジュールを登録します。したがって、これらのモジュールは、このファイルにscriptタグを追加すると、SystemJS内で直接使用できます。あなたのコマンドで

<script src="lib/out.js"></script> 

<script> 
    System.import('main') 
     .then(null, console.error.bind(console)); 
</script> 
+0

私は、コンソールに次のエラー取得しています:例外:セレクタ「私のアプリは、」あなたはまだHTMLファイル内に「私のアプリ」タグを持っていますか – SilverJan

+0

任意の要素を一致しませんでしたか? –

+0

ねえ!私は今、その回避策で生きると思う..あなたの助けをありがとう、本当にそれを感謝する – SilverJan

関連する問題