N
N
nuclear_kote2016-05-24 12:36:01
Angular
nuclear_kote, 2016-05-24 12:36:01

How to use $compile correctly?

I'm trying to make an attribute directive, when hung, the current element will be copied via $(element).clone() and added before the current element, somehow modified and somehow moved by ondrag. The problem is that it has dynamic content, so you need to compile it. If I try to do $compile(clone)(scope); when preparing a clone, the application crashes from stackoverflow, if I compile in onDrag, wild brakes start.

function link(scope, element, attrs) {
....
     $ionicGesture.on('dragright' onDrag, element);
     clone = $(element).clone();
     wrapper = $('<div> </div>').append(clone);
     clone.css('position', 'absolute');
     
     element.before(wrapper);
     $compile(wrapper)(scope); //stack overflow
     
    $compile(wrapper)(scope, function (clonned) { //опять stack overflow
     element.before(clonned);
    }); 

    function onDrag() {
     clone.css('left', ....) ;
     $compile(wrapper)(scope); //Работает, но с дикими тормозами + контент {{}} успевает показаться
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-05-24
@nuclear_kote

So it's not surprising that stackoverflow. You call compile on the cloned element. Compile calls the link function -> call compile -> clone the element and call compile -> call the link function ....
What do you want to end up with?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question