2013-05-30 48 views
1

使用角度綁定真正有幫助,而不是jQuery來操縱DOM,但我不知道如何處理沒有jQuery的拖動事件,例如,我想要拖動第二個框到第一個或拖動-repeat li更改訂單角度js是否有拖動事件或拖動指令?

確實有角度拖動事件或指令?

<div> 
<li>This is first box</li> 
<li>This is second box</li> 
</div> 

//or like below 
<div><li ng-repeat="box in boxs | orderBy:'order'">{{box.name}}{{box.order}}</li></div> 
+0

你試過嗎? http://angular-ui.github.io/ng-grid/ – finishingmove

+0

或者http://codef0rmer.github.io/angular-dragdrop/#/ – finishingmove

+0

你需要這個問題的更多幫助嗎? –

回答

3

您可以

https://github.com/angular-ui/ui-sortable

包括您的文檔中的文件sortable.js實現這一目標。 (請注意:jQuery和jQueryUI的額外依賴)

作爲一個依賴添加排序模塊到應用程序模塊

var myAppModule = angular.module('MyApp', ['ui.sortable']) 

然後改變你的標記是這樣的:

<ul ui-sortable="sortableOptions" ng-model="boxs"> 
    <li ng-repeat="box in boxs | orderBy:'order'"> 
     {{box.name}}{{box.order}} 
    </li> 
</ul> 

最後添加一些您的控制器中的「可排序」配置。

$scope.sortableOptions = { 
    update: function(e, ui) { 
     // do something when the sortorder has changed 
     // e.g. save the new order to your backend... 
    } 
};