我正在使用this示例
我做的完全相同,但我收到以下错误
angular.js:14525 Error: [$injector:unpr] Unknown provider: $elementProvider <- $element <- DragulardndCtrl
http://errors.angularjs.org/1.6.4/$injector/unpr?p0=%24elementProvider%20%3C-%20%24element%20%3C-%20DragulardndCtrl
at angular.js:66
at angular.js:4789
at Object.getService [as get] (angular.js:4944)
at angular.js:4794
at getService (angular.js:4944)
at injectionArgs (angular.js:4969)
at Object.instantiate (angular.js:5015)
at $controller (angular.js:10881)
at Object.link (angular-route.js:1214)
at angular.js:1346 "<div ng-view="" class="ng-scope">"
我用自然角度生成了项目。代码如下:
Controller :
angular.module('dragdropApp')
.controller('DragulardndCtrl', ['$scope', '$element', 'dragularService', function TodoCtrl($scope, $element, dragularService) {
$scope.items1 = [{
content: 'Move me, but you can only drop me in one of these containers.'
}, {
content: 'If you try to drop me somewhere other than these containers, I\'ll just come back.'
}, {
content: 'Item 3'
}, {
content: 'Item 4'
}];
$scope.items2 = [{
content: 'Item 5'
}, {
content: 'Item 6'
}, {
content: 'Item 7'
}, {
content: 'Item 8'
}];
var containers = $element.children().children();
dragularService([containers[0],containers[1]],{
containersModel: [$scope.items1, $scope.items2]
});
}])
HTML:查看
<div class='tableRow'>
<div class='containerVertical'>
<div ng-repeat="item in items1">{{item.content}}</div>
</div>
<div class='containerVertical'>
<div ng-repeat="item in items2">{{item.content}}</div>
</div>
</div>
<div class="tableRow">
<div class="container">
<div>Items1:
<br/>{{items1 | json}}</div>
</div>
<div class="container">
<div>Items2:
<br/>{{items2 | json}}</div>
</div>
</div>
我使用了与上述链接完全相同的代码。
提前致谢
答案 0 :(得分:2)
您可以删除$ element依赖,但不需要dragular。它只需要一些类似于数组的元素集合,这些元素被认为是容器。它可以是
containers = [ document.getElementById('container1'), document.getElementById('container1') ]
或
containers = document.getElementsByClassname('container')
或
containers = document.querySelectorAll('.container')
或者如果您使用的是jQuery
containers = $('.container')
等。