0

Here is my plnkr http://plnkr.co/edit/U5WiZzhX31ifux33enYh

I'm writing a in-place editor directive. It works as expected first time but subsequent times Save or Cancel buttons does not work. Why is that?

In plnkr when I click Save or Cancel 2nd time, it does nothing but in my local dev environment it reloads page.

I'm angular newbie, appreciate your help. Thanks!

1 Answer 1

4

If you remove the editor element from the DOM you will have to recompile the template before adding it again, or otherwise you will loose access to the scope.

Change your show function to something like this:

function show(){        
    editor = $compile(template)(scope);
    element.after(editor);
    element.hide();
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that was really simple! I had a feeling that I was losing binding but I got confused since the template was coming up every time; didn't know I was losing scope.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.