Q:

Angular + jquery ui sortable

Look in this fiddle https://jsfiddle.net/Lj0swckj/3/
I have created directive for sortable
For parent divs sortable working fine
I want same thing for childs also with containment as its parent
In the given example child1, child2, child3 can swap positions and containment will be parent1.
I tried a lot but can't find anything
Note: There can also children for a child1, child2...
(Here In this example i have added data for two levels but it can be upto four levels)
So I want a solution where sortable can work for such kind of recursive templates.
Any Help would be appreciated.

angular.module("myApp", []).
controller("myController", ['$scope', function($scope) {
    $scope.fields = [{
      "name": "parent1",
        "level": 1,
        "children": [{
           "name": "child1",
            "level": 2
        }, {
          "name": "child2",
            "level": 2
        }, {
          "name": "child3",
            "level": 2
        }]
    }, {
      "name": "parent2",
        "level": 1
    }, {
      "name": "parent3",
        "level": 1
    }];
    
    $scope.draggableItemsOption = {
     "moverElement": ".moverBtn",
   "containment": ".draggable-field"
    }
}]).directive("myDragDrop", ['$timeout', function ($timeout) {

  return {
   restrict:'A',
   scope: {
    myDragDrop:"="
   },
   link: function ($scope, element, attrs) {
    var options = $scope.myDragDrop;
    var $container = element;
   
    
    var sortableOptions = {
          /* handle: options.moverElement, */
           containment: options.containment,
           delay: 0
     };


    if($container.sortable){
     $container.sortable(sortableOptions);
    }
    
       }
       }
     
 }]);
.element {
   border: 1px solid #333;
   padding: 10px 10px;
   position: relative;
}

.element-class {
  margin-left: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController">
    
    <div class="draggable-field" my-drag-drop="draggableItemsOption">
        <div ng-repeat="data in fields">
            <div class="element" ng-class="{'element-class': data.level > 1}"> 
              {{data.name}}
              <div ng-repeat="childData in data.children">
                  <div class="element" ng-class="{'element-class': data.level > 1}"> 
                    {{childData.name}}
                   </div>
              </div>
           </div>
      </div>
    </div>
</div>

A:

Huh ! Finally Got a solution.
Actually it is pretty simple
Here look at this fiddle https://jsfiddle.net/Lj0swckj/6/
 What I did is created child elems

angular.module("myApp", []).
controller("myController", ['$scope', function($scope) {
    $scope.fields = [{
      "name": "parent1",
        "level": 1,
        "children": [{
           "name": "child1",
            "level": 2
        }, {
          "name": "child2",
            "level": 2
        }, {
          "name": "child3",
            "level": 2,
            "children": [{
              "name": "grandChild1",
                "level": 3
            }, {
              "name": "grandChild2",
                "level": 3
            }]
        }]
    }, {
      "name": "parent2",
        "level": 1,
        "children": [{
         "name": "child4",
          "level":2
        }]
    }, {
      "name": "parent3",
        "level": 1
    }];
    
    $scope.draggableItemsOption = {
     "moverElement": ".moverBtn",
   "containment": ".draggable-field"
    }
    
    $scope.childDraggableItemsOption = {
      "containment": "parent"
    }
}]).directive("myDragDrop", ['$timeout', function ($timeout) {

  return {
   restrict:'A',
   scope: {
    myDragDrop:"="
   },
   link: function ($scope, element, attrs) {

    var options = $scope.myDragDrop;
    var $container = element;
   
    
    var sortableOptions = {
          /* handle: options.moverElement, */
           containment: options.containment,
           delay: 0
     };


    if($container.sortable){
     $container.sortable(sortableOptions);
    }
    
       }
       }
     
 }]);
.element {
   border: 1px solid #333;
   padding: 10px 10px;
   position: relative;
}

.element-class {
  margin-left: 20px;
}

.moverBtn {
  position: absolute;
  top: 2px;
  right: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-autocomplete/1.0.7/jquery.auto-complete.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>

<div ng-app="myApp" ng-controller="myController">
    <script type="text/ng-template"  id="tree_item_renderer.html">
    <div class="child-draggable-field" my-drag-drop="childDraggableItemsOption">
      <div ng-repeat="data in data.children" ng-class="{'element-class': data.level > 1}">
        <div class="element"> {{data.name}} ------ {{$parent.$parent.data.children.length}}</div>
          <div ng-include="'tree_item_renderer.html'">
              </div>
       </div>
    </div>
</script>
    <div class="draggable-field" my-drag-drop="draggableItemsOption">
        <div ng-repeat="data in fields">
            <div class="element" ng-class="{'element-class': data.level > 1}"> 
              {{data.name}}
              <div ng-include="'tree_item_renderer.html'">
              </div>
           </div>
      </div>
    </div>
</div>

