mhtsbt
mhtsbt

Reputation: 1079

Move $scope to other parent in scope-tree

I'm currently building something grid-like that requires cells (directives) to be moved inside the dom.

When I move an element inside the DOM I would like to update the scope-tree as well. Say for example I start with something like this:

<div with scope1>
   <directive with scope2>
</div with scope1>

<div with scope3>
   <directive with scope4>
</div with scope2>

When I move "directive with scope2" to the "diw with scope3":

<div with scope1>       
</div with scope1>

<div with scope3>
   <directive with scope4>
   <directive with scope2>
</div with scope2>

Then my scope tree doesn't get updated. So "directive with scope2" still has scope1 as its parent.

Is it possible in some way to manually set the parent scope of "directive with scope2" to become "div with scope3" instead of "div with scope1".

Thx!

Upvotes: 2

Views: 305

Answers (1)

Pierre Gayvallet
Pierre Gayvallet

Reputation: 2953

You are thinking 'DOM' when you should be thinking 'model'

Basic approach should be :

Parents directive have a parent model which contains a list of children. Parent template ng-repeat on the children

<my-child-directive ng-repeat="child in myModel.children"

Move a model from a parent children list to another, the DOM updates. Et voila.

Upvotes: 1

Related Questions