ng2-dragula 看起来很酷,但我很难为我的 angular 2 项目设置它。我system.js
用作模块预加载器,它的配置是:
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