我會建議使用Ng2-Dragula。
它是angular2依賴項,它爲您的應用程序輕鬆提供拖放功能。
所有你需要做的就是通過npm來安裝這個依賴。
npm install ng2-dragula dragula --save
插件包括內部的index.html和配置系統
<script src="/node_modules/ng2-dragula/bundles/ng2-dragula.js"></script>
<link href="/node_modules/ng2-dragula/src/public/css/dragula.min.css" rel='stylesheet' type='text/css'>
<script>
System.config({
paths:{
'dragula' : '../node_modules/dragula/dist/dragula.min.js'
},
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/main')
.then(null, console.error.bind(console));
</script>
進口它要使用拖放n個墨滴在組件內部,你是好去。
@Component({
selector: 'sample',
directives: [Dragula],
viewProviders: [DragulaService],
template:`
<div>
<div class='wrapper'>
<div class='container' [dragula]='"first-bag"'>
<div>You can move these elements between these two containers</div>
<div>Moving them anywhere else isn't quite possible</div>
<div>There's also the possibility of moving elements around in the same container, changing their position</div>
</div>
<div class='container' [dragula]='"first-bag"'>
<div>This is the default use case. You only need to specify the containers you want to use</div>
<div>More interactive use cases lie ahead</div>
<div>Make sure to check out the <a href='https://github.com/bevacqua/dragula#readme'>documentation on GitHub!</a></div>
</div>
</div>
</div>
`
})
class Sample {}
我意識到我忘了將指令添加到組件指令列表中。儘管現在似乎EventEmitter上的.toRx方法不再可用。應該如何改變? – theva
從Beta 1開始,[你不再需要在發射器上調用.toRx()](http://stackoverflow.com/questions/33530726/angular-2-eventemitter-broadcasting-next-from-a-service-功能/ 33534404#33534404)。 –
這是相當不錯的描述在這裏http://stackoverflow.com/a/38710223/2173016 –