angularjsdrag-and-dropdragular

$injector:unpr :: Unknown provider: $elementProvider <- $element <- DragulardndCtrl


I am using this example

I am doing exactly the same but I am getting the following error

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">"

I have generated the project with yeoman angular.The codes are given below

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:View

<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>

I have used exactly the same code from the above-mentioned link.

Thanks in advance


Solution

  • You can remove $element dependecy, it is not needed for dragular. It only needs some array-like collection of elements which are considered to be containers. It can be

    containers = [ document.getElementById('container1'), document.getElementById('container1') ]
    

    or

    containers = document.getElementsByClassname('container')
    

    or

    containers = document.querySelectorAll('.container')
    

    or if you are using jQuery

    containers = $('.container')
    

    etc..