2016-02-29 61 views
0

NG2-dragula加載外部模塊看起來很酷,但我有一些很難將其設置爲我的角2項目。我用system.js作爲模塊預加載和它的配置是:錯誤:要求是不是一個函數,而在角2

System.config({ 
    packages: {   
     app: { 
     format: 'register', 
     defaultExtension: 'js' 
     }, 
     'ng2-bootstrap': {}, 
     'ng2-dragula': { defaultExtension: 'js' } 
    }, 
    map: { 
     'dragula': 'node_modules/dragula', 
     'ng2-bootstrap': 'node_modules/ng2-bootstrap', 
     'ng2-dragula': 'node_modules/ng2-dragula', 
     'moment': 'node_modules/moment/moment.js' 
    } 
}); 

tsconfig.json

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "system", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false, 
    "watch": true 
    } 
} 

我如下加載它在我的組件:

import {DragulaService, Dragula} from 'ng2-dragula/ng2-dragula' 

@Component({ 
    selector: 'my-cmp', 
    viewProviders: [DragulaService], 
}) 


@View({ 
    template: '<div>Hey</div>', 
    directives: [Dragula] 
}) 

我在做什麼錯誤,導致我在瀏覽器中出現以下錯誤:

Error: require is not a function(…) angular2-polyfills.js:1243 

回答

2

您可能正在通過<script src="some-module.js">標籤加載一些編譯爲commonjs模塊的腳本。您應該刪除它們的使用System.import("some-module.js")代替。見this answer關於類似問題的解釋。

相關問題